
obj/user/testpiperace2:     file format elf32-i386


Disassembly of section .text:

00800020 <_start>:
// starts us running when we are initially loaded into a new environment.
.text
.globl _start
_start:
	// See if we were started with arguments on the stack
	cmpl $USTACKTOP, %esp
  800020:	81 fc 00 e0 bf ee    	cmp    $0xeebfe000,%esp
	jne args_exist
  800026:	75 04                	jne    80002c <args_exist>

	// If not, push dummy argc/argv arguments.
	// This happens when we are loaded by the kernel,
	// because the kernel does not know about passing arguments.
	pushl $0
  800028:	6a 00                	push   $0x0
	pushl $0
  80002a:	6a 00                	push   $0x0

0080002c <args_exist>:

args_exist:
	call libmain
  80002c:	e8 bb 01 00 00       	call   8001ec <libmain>
1:	jmp 1b
  800031:	eb fe                	jmp    800031 <args_exist+0x5>
	...

00800034 <umain>:

#include <inc/lib.h>

void
umain(void)
{
  800034:	55                   	push   %ebp
  800035:	89 e5                	mov    %esp,%ebp
  800037:	57                   	push   %edi
  800038:	56                   	push   %esi
  800039:	53                   	push   %ebx
  80003a:	83 ec 2c             	sub    $0x2c,%esp
	int p[2], r, i;
	struct Fd *fd;
	volatile struct Env *kid;

	cprintf("testing for pipeisclosed race...\n");
  80003d:	c7 04 24 20 2e 80 00 	movl   $0x802e20,(%esp)
  800044:	e8 d4 02 00 00       	call   80031d <cprintf>
	if ((r = pipe(p)) < 0)
  800049:	8d 45 e0             	lea    -0x20(%ebp),%eax
  80004c:	89 04 24             	mov    %eax,(%esp)
  80004f:	e8 75 26 00 00       	call   8026c9 <pipe>
  800054:	85 c0                	test   %eax,%eax
  800056:	79 20                	jns    800078 <umain+0x44>
		panic("pipe: %e", r);
  800058:	89 44 24 0c          	mov    %eax,0xc(%esp)
  80005c:	c7 44 24 08 6e 2e 80 	movl   $0x802e6e,0x8(%esp)
  800063:	00 
  800064:	c7 44 24 04 0d 00 00 	movl   $0xd,0x4(%esp)
  80006b:	00 
  80006c:	c7 04 24 77 2e 80 00 	movl   $0x802e77,(%esp)
  800073:	e8 e0 01 00 00       	call   800258 <_panic>
	if ((r = fork()) < 0)
  800078:	e8 15 12 00 00       	call   801292 <fork>
  80007d:	89 c7                	mov    %eax,%edi
  80007f:	85 c0                	test   %eax,%eax
  800081:	79 20                	jns    8000a3 <umain+0x6f>
		panic("fork: %e", r);
  800083:	89 44 24 0c          	mov    %eax,0xc(%esp)
  800087:	c7 44 24 08 8c 2e 80 	movl   $0x802e8c,0x8(%esp)
  80008e:	00 
  80008f:	c7 44 24 04 0f 00 00 	movl   $0xf,0x4(%esp)
  800096:	00 
  800097:	c7 04 24 77 2e 80 00 	movl   $0x802e77,(%esp)
  80009e:	e8 b5 01 00 00       	call   800258 <_panic>
	if (r == 0) {
  8000a3:	85 c0                	test   %eax,%eax
  8000a5:	75 75                	jne    80011c <umain+0xe8>
		// child just dups and closes repeatedly,
		// yielding so the parent can see
		// the fd state between the two.
		close(p[1]);
  8000a7:	8b 45 e4             	mov    -0x1c(%ebp),%eax
  8000aa:	89 04 24             	mov    %eax,(%esp)
  8000ad:	e8 7a 1a 00 00       	call   801b2c <close>
  8000b2:	bb 00 00 00 00       	mov    $0x0,%ebx
		for (i = 0; i < 200; i++) {
			if (i % 10 == 0)
  8000b7:	be 67 66 66 66       	mov    $0x66666667,%esi
  8000bc:	89 d8                	mov    %ebx,%eax
  8000be:	f7 ee                	imul   %esi
  8000c0:	c1 fa 02             	sar    $0x2,%edx
  8000c3:	89 d8                	mov    %ebx,%eax
  8000c5:	c1 f8 1f             	sar    $0x1f,%eax
  8000c8:	29 c2                	sub    %eax,%edx
  8000ca:	8d 04 92             	lea    (%edx,%edx,4),%eax
  8000cd:	01 c0                	add    %eax,%eax
  8000cf:	39 c3                	cmp    %eax,%ebx
  8000d1:	75 10                	jne    8000e3 <umain+0xaf>
				cprintf("%d.", i);
  8000d3:	89 5c 24 04          	mov    %ebx,0x4(%esp)
  8000d7:	c7 04 24 95 2e 80 00 	movl   $0x802e95,(%esp)
  8000de:	e8 3a 02 00 00       	call   80031d <cprintf>
			// dup, then close.  yield so that other guy will
			// see us while we're between them.
			dup(p[0], 10);
  8000e3:	c7 44 24 04 0a 00 00 	movl   $0xa,0x4(%esp)
  8000ea:	00 
  8000eb:	8b 45 e0             	mov    -0x20(%ebp),%eax
  8000ee:	89 04 24             	mov    %eax,(%esp)
  8000f1:	e8 d5 1a 00 00       	call   801bcb <dup>
			sys_yield();
  8000f6:	e8 aa 10 00 00       	call   8011a5 <sys_yield>
			close(10);
  8000fb:	c7 04 24 0a 00 00 00 	movl   $0xa,(%esp)
  800102:	e8 25 1a 00 00       	call   801b2c <close>
			sys_yield();
  800107:	e8 99 10 00 00       	call   8011a5 <sys_yield>
	if (r == 0) {
		// child just dups and closes repeatedly,
		// yielding so the parent can see
		// the fd state between the two.
		close(p[1]);
		for (i = 0; i < 200; i++) {
  80010c:	83 c3 01             	add    $0x1,%ebx
  80010f:	81 fb c8 00 00 00    	cmp    $0xc8,%ebx
  800115:	75 a5                	jne    8000bc <umain+0x88>
			dup(p[0], 10);
			sys_yield();
			close(10);
			sys_yield();
		}
		exit();
  800117:	e8 20 01 00 00       	call   80023c <exit>
	// pageref(p[0]) and gets 3, then it will return true when
	// it shouldn't.
	//
	// So either way, pipeisclosed is going give a wrong answer.
	//
	kid = &envs[ENVX(r)];
  80011c:	89 fb                	mov    %edi,%ebx
  80011e:	81 e3 ff 03 00 00    	and    $0x3ff,%ebx
  800124:	6b db 7c             	imul   $0x7c,%ebx,%ebx
  800127:	81 c3 00 00 c0 ee    	add    $0xeec00000,%ebx
	while (kid->env_status == ENV_RUNNABLE)
  80012d:	eb 28                	jmp    800157 <umain+0x123>
		if (pipeisclosed(p[0]) != 0) {
  80012f:	8b 45 e0             	mov    -0x20(%ebp),%eax
  800132:	89 04 24             	mov    %eax,(%esp)
  800135:	e8 5c 25 00 00       	call   802696 <pipeisclosed>
  80013a:	85 c0                	test   %eax,%eax
  80013c:	74 19                	je     800157 <umain+0x123>
			cprintf("\nRACE: pipe appears closed\n");
  80013e:	c7 04 24 99 2e 80 00 	movl   $0x802e99,(%esp)
  800145:	e8 d3 01 00 00       	call   80031d <cprintf>
			sys_env_destroy(r);
  80014a:	89 3c 24             	mov    %edi,(%esp)
  80014d:	e8 bb 10 00 00       	call   80120d <sys_env_destroy>
			exit();
  800152:	e8 e5 00 00 00       	call   80023c <exit>
	// it shouldn't.
	//
	// So either way, pipeisclosed is going give a wrong answer.
	//
	kid = &envs[ENVX(r)];
	while (kid->env_status == ENV_RUNNABLE)
  800157:	8b 43 54             	mov    0x54(%ebx),%eax
  80015a:	83 f8 01             	cmp    $0x1,%eax
  80015d:	74 d0                	je     80012f <umain+0xfb>
		if (pipeisclosed(p[0]) != 0) {
			cprintf("\nRACE: pipe appears closed\n");
			sys_env_destroy(r);
			exit();
		}
	cprintf("child done with loop\n");
  80015f:	c7 04 24 b5 2e 80 00 	movl   $0x802eb5,(%esp)
  800166:	e8 b2 01 00 00       	call   80031d <cprintf>
	if (pipeisclosed(p[0]))
  80016b:	8b 45 e0             	mov    -0x20(%ebp),%eax
  80016e:	89 04 24             	mov    %eax,(%esp)
  800171:	e8 20 25 00 00       	call   802696 <pipeisclosed>
  800176:	85 c0                	test   %eax,%eax
  800178:	74 1c                	je     800196 <umain+0x162>
		panic("somehow the other end of p[0] got closed!");
  80017a:	c7 44 24 08 44 2e 80 	movl   $0x802e44,0x8(%esp)
  800181:	00 
  800182:	c7 44 24 04 40 00 00 	movl   $0x40,0x4(%esp)
  800189:	00 
  80018a:	c7 04 24 77 2e 80 00 	movl   $0x802e77,(%esp)
  800191:	e8 c2 00 00 00       	call   800258 <_panic>
	if ((r = fd_lookup(p[0], &fd)) < 0)
  800196:	8d 45 dc             	lea    -0x24(%ebp),%eax
  800199:	89 44 24 04          	mov    %eax,0x4(%esp)
  80019d:	8b 45 e0             	mov    -0x20(%ebp),%eax
  8001a0:	89 04 24             	mov    %eax,(%esp)
  8001a3:	e8 65 15 00 00       	call   80170d <fd_lookup>
  8001a8:	85 c0                	test   %eax,%eax
  8001aa:	79 20                	jns    8001cc <umain+0x198>
		panic("cannot look up p[0]: %e", r);
  8001ac:	89 44 24 0c          	mov    %eax,0xc(%esp)
  8001b0:	c7 44 24 08 cb 2e 80 	movl   $0x802ecb,0x8(%esp)
  8001b7:	00 
  8001b8:	c7 44 24 04 42 00 00 	movl   $0x42,0x4(%esp)
  8001bf:	00 
  8001c0:	c7 04 24 77 2e 80 00 	movl   $0x802e77,(%esp)
  8001c7:	e8 8c 00 00 00       	call   800258 <_panic>
	(void) fd2data(fd);
  8001cc:	8b 45 dc             	mov    -0x24(%ebp),%eax
  8001cf:	89 04 24             	mov    %eax,(%esp)
  8001d2:	e8 a9 14 00 00       	call   801680 <fd2data>
	cprintf("race didn't happen\n");
  8001d7:	c7 04 24 e3 2e 80 00 	movl   $0x802ee3,(%esp)
  8001de:	e8 3a 01 00 00       	call   80031d <cprintf>
}
  8001e3:	83 c4 2c             	add    $0x2c,%esp
  8001e6:	5b                   	pop    %ebx
  8001e7:	5e                   	pop    %esi
  8001e8:	5f                   	pop    %edi
  8001e9:	5d                   	pop    %ebp
  8001ea:	c3                   	ret    
	...

008001ec <libmain>:
volatile struct Env *env;
char *binaryname = "(PROGRAM NAME UNKNOWN)";

void
libmain(int argc, char **argv)
{
  8001ec:	55                   	push   %ebp
  8001ed:	89 e5                	mov    %esp,%ebp
  8001ef:	83 ec 18             	sub    $0x18,%esp
  8001f2:	89 5d f8             	mov    %ebx,-0x8(%ebp)
  8001f5:	89 75 fc             	mov    %esi,-0x4(%ebp)
  8001f8:	8b 75 08             	mov    0x8(%ebp),%esi
  8001fb:	8b 5d 0c             	mov    0xc(%ebp),%ebx
	// set env to point at our env structure in envs[].
	// LAB 3: Your code here.
  envid_t envid   = sys_getenvid();
  8001fe:	e8 d6 0f 00 00       	call   8011d9 <sys_getenvid>
	env = &envs [ENVX(envid)];
  800203:	25 ff 03 00 00       	and    $0x3ff,%eax
  800208:	6b c0 7c             	imul   $0x7c,%eax,%eax
  80020b:	05 00 00 c0 ee       	add    $0xeec00000,%eax
  800210:	a3 74 70 80 00       	mov    %eax,0x807074

	// save the name of the program so that panic() can use it
	if (argc > 0)
  800215:	85 f6                	test   %esi,%esi
  800217:	7e 07                	jle    800220 <libmain+0x34>
		binaryname = argv[0];
  800219:	8b 03                	mov    (%ebx),%eax
  80021b:	a3 00 70 80 00       	mov    %eax,0x807000

	// call user main routine
	umain(argc, argv);
  800220:	89 5c 24 04          	mov    %ebx,0x4(%esp)
  800224:	89 34 24             	mov    %esi,(%esp)
  800227:	e8 08 fe ff ff       	call   800034 <umain>

	// exit gracefully
	exit();
  80022c:	e8 0b 00 00 00       	call   80023c <exit>
}
  800231:	8b 5d f8             	mov    -0x8(%ebp),%ebx
  800234:	8b 75 fc             	mov    -0x4(%ebp),%esi
  800237:	89 ec                	mov    %ebp,%esp
  800239:	5d                   	pop    %ebp
  80023a:	c3                   	ret    
	...

0080023c <exit>:

#include <inc/lib.h>

void
exit(void)
{
  80023c:	55                   	push   %ebp
  80023d:	89 e5                	mov    %esp,%ebp
  80023f:	83 ec 18             	sub    $0x18,%esp
	close_all();
  800242:	e8 62 19 00 00       	call   801ba9 <close_all>
	sys_env_destroy(0);
  800247:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  80024e:	e8 ba 0f 00 00       	call   80120d <sys_env_destroy>
}
  800253:	c9                   	leave  
  800254:	c3                   	ret    
  800255:	00 00                	add    %al,(%eax)
	...

00800258 <_panic>:
 * It prints "panic: <message>", then causes a breakpoint exception,
 * which causes JOS to enter the JOS kernel monitor.
 */
void
_panic(const char *file, int line, const char *fmt,...)
{
  800258:	55                   	push   %ebp
  800259:	89 e5                	mov    %esp,%ebp
  80025b:	53                   	push   %ebx
  80025c:	83 ec 14             	sub    $0x14,%esp
 * Panic is called on unresolvable fatal errors.
 * It prints "panic: <message>", then causes a breakpoint exception,
 * which causes JOS to enter the JOS kernel monitor.
 */
void
_panic(const char *file, int line, const char *fmt,...)
  80025f:	8d 5d 14             	lea    0x14(%ebp),%ebx
	va_list ap;

	va_start(ap, fmt);

	// Print the panic message
	if (argv0)
  800262:	a1 78 70 80 00       	mov    0x807078,%eax
  800267:	85 c0                	test   %eax,%eax
  800269:	74 10                	je     80027b <_panic+0x23>
		cprintf("%s: ", argv0);
  80026b:	89 44 24 04          	mov    %eax,0x4(%esp)
  80026f:	c7 04 24 0e 2f 80 00 	movl   $0x802f0e,(%esp)
  800276:	e8 a2 00 00 00       	call   80031d <cprintf>
	cprintf("user panic in %s at %s:%d: ", binaryname, file, line);
  80027b:	8b 45 0c             	mov    0xc(%ebp),%eax
  80027e:	89 44 24 0c          	mov    %eax,0xc(%esp)
  800282:	8b 45 08             	mov    0x8(%ebp),%eax
  800285:	89 44 24 08          	mov    %eax,0x8(%esp)
  800289:	a1 00 70 80 00       	mov    0x807000,%eax
  80028e:	89 44 24 04          	mov    %eax,0x4(%esp)
  800292:	c7 04 24 13 2f 80 00 	movl   $0x802f13,(%esp)
  800299:	e8 7f 00 00 00       	call   80031d <cprintf>
	vcprintf(fmt, ap);
  80029e:	89 5c 24 04          	mov    %ebx,0x4(%esp)
  8002a2:	8b 45 10             	mov    0x10(%ebp),%eax
  8002a5:	89 04 24             	mov    %eax,(%esp)
  8002a8:	e8 0f 00 00 00       	call   8002bc <vcprintf>
	cprintf("\n");
  8002ad:	c7 04 24 a7 32 80 00 	movl   $0x8032a7,(%esp)
  8002b4:	e8 64 00 00 00       	call   80031d <cprintf>

	// Cause a breakpoint exception
	while (1)
		asm volatile("int3");
  8002b9:	cc                   	int3   
  8002ba:	eb fd                	jmp    8002b9 <_panic+0x61>

008002bc <vcprintf>:
	b->cnt++;
}

int
vcprintf(const char *fmt, va_list ap)
{
  8002bc:	55                   	push   %ebp
  8002bd:	89 e5                	mov    %esp,%ebp
  8002bf:	81 ec 28 01 00 00    	sub    $0x128,%esp
	struct printbuf b;

	b.idx = 0;
  8002c5:	c7 85 f0 fe ff ff 00 	movl   $0x0,-0x110(%ebp)
  8002cc:	00 00 00 
	b.cnt = 0;
  8002cf:	c7 85 f4 fe ff ff 00 	movl   $0x0,-0x10c(%ebp)
  8002d6:	00 00 00 
	vprintfmt((void*)putch, &b, fmt, ap);
  8002d9:	8b 45 0c             	mov    0xc(%ebp),%eax
  8002dc:	89 44 24 0c          	mov    %eax,0xc(%esp)
  8002e0:	8b 45 08             	mov    0x8(%ebp),%eax
  8002e3:	89 44 24 08          	mov    %eax,0x8(%esp)
  8002e7:	8d 85 f0 fe ff ff    	lea    -0x110(%ebp),%eax
  8002ed:	89 44 24 04          	mov    %eax,0x4(%esp)
  8002f1:	c7 04 24 37 03 80 00 	movl   $0x800337,(%esp)
  8002f8:	e8 d0 01 00 00       	call   8004cd <vprintfmt>
	sys_cputs(b.buf, b.idx);
  8002fd:	8b 85 f0 fe ff ff    	mov    -0x110(%ebp),%eax
  800303:	89 44 24 04          	mov    %eax,0x4(%esp)
  800307:	8d 85 f8 fe ff ff    	lea    -0x108(%ebp),%eax
  80030d:	89 04 24             	mov    %eax,(%esp)
  800310:	e8 cb 0a 00 00       	call   800de0 <sys_cputs>

	return b.cnt;
}
  800315:	8b 85 f4 fe ff ff    	mov    -0x10c(%ebp),%eax
  80031b:	c9                   	leave  
  80031c:	c3                   	ret    

0080031d <cprintf>:

int
cprintf(const char *fmt, ...)
{
  80031d:	55                   	push   %ebp
  80031e:	89 e5                	mov    %esp,%ebp
  800320:	83 ec 18             	sub    $0x18,%esp

	return b.cnt;
}

int
cprintf(const char *fmt, ...)
  800323:	8d 45 0c             	lea    0xc(%ebp),%eax
{
	va_list ap;
	int cnt;

	va_start(ap, fmt);
	cnt = vcprintf(fmt, ap);
  800326:	89 44 24 04          	mov    %eax,0x4(%esp)
  80032a:	8b 45 08             	mov    0x8(%ebp),%eax
  80032d:	89 04 24             	mov    %eax,(%esp)
  800330:	e8 87 ff ff ff       	call   8002bc <vcprintf>
	va_end(ap);

	return cnt;
}
  800335:	c9                   	leave  
  800336:	c3                   	ret    

00800337 <putch>:
};


static void
putch(int ch, struct printbuf *b)
{
  800337:	55                   	push   %ebp
  800338:	89 e5                	mov    %esp,%ebp
  80033a:	53                   	push   %ebx
  80033b:	83 ec 14             	sub    $0x14,%esp
  80033e:	8b 5d 0c             	mov    0xc(%ebp),%ebx
	b->buf[b->idx++] = ch;
  800341:	8b 03                	mov    (%ebx),%eax
  800343:	8b 55 08             	mov    0x8(%ebp),%edx
  800346:	88 54 03 08          	mov    %dl,0x8(%ebx,%eax,1)
  80034a:	83 c0 01             	add    $0x1,%eax
  80034d:	89 03                	mov    %eax,(%ebx)
	if (b->idx == 256-1) {
  80034f:	3d ff 00 00 00       	cmp    $0xff,%eax
  800354:	75 19                	jne    80036f <putch+0x38>
		sys_cputs(b->buf, b->idx);
  800356:	c7 44 24 04 ff 00 00 	movl   $0xff,0x4(%esp)
  80035d:	00 
  80035e:	8d 43 08             	lea    0x8(%ebx),%eax
  800361:	89 04 24             	mov    %eax,(%esp)
  800364:	e8 77 0a 00 00       	call   800de0 <sys_cputs>
		b->idx = 0;
  800369:	c7 03 00 00 00 00    	movl   $0x0,(%ebx)
	}
	b->cnt++;
  80036f:	83 43 04 01          	addl   $0x1,0x4(%ebx)
}
  800373:	83 c4 14             	add    $0x14,%esp
  800376:	5b                   	pop    %ebx
  800377:	5d                   	pop    %ebp
  800378:	c3                   	ret    
  800379:	00 00                	add    %al,(%eax)
  80037b:	00 00                	add    %al,(%eax)
  80037d:	00 00                	add    %al,(%eax)
	...

00800380 <printnum>:
 * using specified putch function and associated pointer putdat.
 */
static void
printnum(void (*putch)(int, void*), void *putdat,
	 unsigned long long num, unsigned base, int width, int padc)
{
  800380:	55                   	push   %ebp
  800381:	89 e5                	mov    %esp,%ebp
  800383:	57                   	push   %edi
  800384:	56                   	push   %esi
  800385:	53                   	push   %ebx
  800386:	83 ec 4c             	sub    $0x4c,%esp
  800389:	89 45 e4             	mov    %eax,-0x1c(%ebp)
  80038c:	89 d6                	mov    %edx,%esi
  80038e:	8b 45 08             	mov    0x8(%ebp),%eax
  800391:	89 45 d8             	mov    %eax,-0x28(%ebp)
  800394:	8b 55 0c             	mov    0xc(%ebp),%edx
  800397:	89 55 e0             	mov    %edx,-0x20(%ebp)
  80039a:	8b 45 10             	mov    0x10(%ebp),%eax
  80039d:	8b 5d 14             	mov    0x14(%ebp),%ebx
  8003a0:	8b 7d 18             	mov    0x18(%ebp),%edi
	// first recursively print all preceding (more significant) digits
	if (num >= base) {
  8003a3:	89 45 dc             	mov    %eax,-0x24(%ebp)
  8003a6:	b9 00 00 00 00       	mov    $0x0,%ecx
  8003ab:	39 d1                	cmp    %edx,%ecx
  8003ad:	72 15                	jb     8003c4 <printnum+0x44>
  8003af:	77 07                	ja     8003b8 <printnum+0x38>
  8003b1:	8b 55 d8             	mov    -0x28(%ebp),%edx
  8003b4:	39 d0                	cmp    %edx,%eax
  8003b6:	76 0c                	jbe    8003c4 <printnum+0x44>
		printnum(putch, putdat, num / base, base, width - 1, padc);
	} else {
		// print any needed pad characters before first digit
		while (--width > 0)
  8003b8:	83 eb 01             	sub    $0x1,%ebx
  8003bb:	85 db                	test   %ebx,%ebx
  8003bd:	8d 76 00             	lea    0x0(%esi),%esi
  8003c0:	7f 61                	jg     800423 <printnum+0xa3>
  8003c2:	eb 70                	jmp    800434 <printnum+0xb4>
printnum(void (*putch)(int, void*), void *putdat,
	 unsigned long long num, unsigned base, int width, int padc)
{
	// first recursively print all preceding (more significant) digits
	if (num >= base) {
		printnum(putch, putdat, num / base, base, width - 1, padc);
  8003c4:	89 7c 24 10          	mov    %edi,0x10(%esp)
  8003c8:	83 eb 01             	sub    $0x1,%ebx
  8003cb:	89 5c 24 0c          	mov    %ebx,0xc(%esp)
  8003cf:	89 44 24 08          	mov    %eax,0x8(%esp)
  8003d3:	8b 4c 24 08          	mov    0x8(%esp),%ecx
  8003d7:	8b 5c 24 0c          	mov    0xc(%esp),%ebx
  8003db:	89 4d d0             	mov    %ecx,-0x30(%ebp)
  8003de:	89 5d d4             	mov    %ebx,-0x2c(%ebp)
  8003e1:	8b 5d dc             	mov    -0x24(%ebp),%ebx
  8003e4:	89 5c 24 08          	mov    %ebx,0x8(%esp)
  8003e8:	c7 44 24 0c 00 00 00 	movl   $0x0,0xc(%esp)
  8003ef:	00 
  8003f0:	8b 45 d8             	mov    -0x28(%ebp),%eax
  8003f3:	89 04 24             	mov    %eax,(%esp)
  8003f6:	8b 55 e0             	mov    -0x20(%ebp),%edx
  8003f9:	89 54 24 04          	mov    %edx,0x4(%esp)
  8003fd:	e8 ae 27 00 00       	call   802bb0 <__udivdi3>
  800402:	8b 4d d0             	mov    -0x30(%ebp),%ecx
  800405:	8b 5d d4             	mov    -0x2c(%ebp),%ebx
  800408:	89 4c 24 08          	mov    %ecx,0x8(%esp)
  80040c:	89 5c 24 0c          	mov    %ebx,0xc(%esp)
  800410:	89 04 24             	mov    %eax,(%esp)
  800413:	89 54 24 04          	mov    %edx,0x4(%esp)
  800417:	89 f2                	mov    %esi,%edx
  800419:	8b 45 e4             	mov    -0x1c(%ebp),%eax
  80041c:	e8 5f ff ff ff       	call   800380 <printnum>
  800421:	eb 11                	jmp    800434 <printnum+0xb4>
	} else {
		// print any needed pad characters before first digit
		while (--width > 0)
			putch(padc, putdat);
  800423:	89 74 24 04          	mov    %esi,0x4(%esp)
  800427:	89 3c 24             	mov    %edi,(%esp)
  80042a:	ff 55 e4             	call   *-0x1c(%ebp)
	// first recursively print all preceding (more significant) digits
	if (num >= base) {
		printnum(putch, putdat, num / base, base, width - 1, padc);
	} else {
		// print any needed pad characters before first digit
		while (--width > 0)
  80042d:	83 eb 01             	sub    $0x1,%ebx
  800430:	85 db                	test   %ebx,%ebx
  800432:	7f ef                	jg     800423 <printnum+0xa3>
			putch(padc, putdat);
	}

	// then print this (the least significant) digit
	putch("0123456789abcdef"[num % base], putdat);
  800434:	89 74 24 04          	mov    %esi,0x4(%esp)
  800438:	8b 74 24 04          	mov    0x4(%esp),%esi
  80043c:	8b 45 dc             	mov    -0x24(%ebp),%eax
  80043f:	89 44 24 08          	mov    %eax,0x8(%esp)
  800443:	c7 44 24 0c 00 00 00 	movl   $0x0,0xc(%esp)
  80044a:	00 
  80044b:	8b 55 d8             	mov    -0x28(%ebp),%edx
  80044e:	89 14 24             	mov    %edx,(%esp)
  800451:	8b 4d e0             	mov    -0x20(%ebp),%ecx
  800454:	89 4c 24 04          	mov    %ecx,0x4(%esp)
  800458:	e8 83 28 00 00       	call   802ce0 <__umoddi3>
  80045d:	89 74 24 04          	mov    %esi,0x4(%esp)
  800461:	0f be 80 2f 2f 80 00 	movsbl 0x802f2f(%eax),%eax
  800468:	89 04 24             	mov    %eax,(%esp)
  80046b:	ff 55 e4             	call   *-0x1c(%ebp)
}
  80046e:	83 c4 4c             	add    $0x4c,%esp
  800471:	5b                   	pop    %ebx
  800472:	5e                   	pop    %esi
  800473:	5f                   	pop    %edi
  800474:	5d                   	pop    %ebp
  800475:	c3                   	ret    

00800476 <getuint>:

// Get an unsigned int of various possible sizes from a varargs list,
// depending on the lflag parameter.
static unsigned long long
getuint(va_list *ap, int lflag)
{
  800476:	55                   	push   %ebp
  800477:	89 e5                	mov    %esp,%ebp
	if (lflag >= 2)
  800479:	83 fa 01             	cmp    $0x1,%edx
  80047c:	7e 0e                	jle    80048c <getuint+0x16>
		return va_arg(*ap, unsigned long long);
  80047e:	8b 10                	mov    (%eax),%edx
  800480:	8d 4a 08             	lea    0x8(%edx),%ecx
  800483:	89 08                	mov    %ecx,(%eax)
  800485:	8b 02                	mov    (%edx),%eax
  800487:	8b 52 04             	mov    0x4(%edx),%edx
  80048a:	eb 22                	jmp    8004ae <getuint+0x38>
	else if (lflag)
  80048c:	85 d2                	test   %edx,%edx
  80048e:	74 10                	je     8004a0 <getuint+0x2a>
		return va_arg(*ap, unsigned long);
  800490:	8b 10                	mov    (%eax),%edx
  800492:	8d 4a 04             	lea    0x4(%edx),%ecx
  800495:	89 08                	mov    %ecx,(%eax)
  800497:	8b 02                	mov    (%edx),%eax
  800499:	ba 00 00 00 00       	mov    $0x0,%edx
  80049e:	eb 0e                	jmp    8004ae <getuint+0x38>
	else
		return va_arg(*ap, unsigned int);
  8004a0:	8b 10                	mov    (%eax),%edx
  8004a2:	8d 4a 04             	lea    0x4(%edx),%ecx
  8004a5:	89 08                	mov    %ecx,(%eax)
  8004a7:	8b 02                	mov    (%edx),%eax
  8004a9:	ba 00 00 00 00       	mov    $0x0,%edx
}
  8004ae:	5d                   	pop    %ebp
  8004af:	c3                   	ret    

008004b0 <sprintputch>:
	int cnt;
};

static void
sprintputch(int ch, struct sprintbuf *b)
{
  8004b0:	55                   	push   %ebp
  8004b1:	89 e5                	mov    %esp,%ebp
  8004b3:	8b 45 0c             	mov    0xc(%ebp),%eax
	b->cnt++;
  8004b6:	83 40 08 01          	addl   $0x1,0x8(%eax)
	if (b->buf < b->ebuf)
  8004ba:	8b 10                	mov    (%eax),%edx
  8004bc:	3b 50 04             	cmp    0x4(%eax),%edx
  8004bf:	73 0a                	jae    8004cb <sprintputch+0x1b>
		*b->buf++ = ch;
  8004c1:	8b 4d 08             	mov    0x8(%ebp),%ecx
  8004c4:	88 0a                	mov    %cl,(%edx)
  8004c6:	83 c2 01             	add    $0x1,%edx
  8004c9:	89 10                	mov    %edx,(%eax)
}
  8004cb:	5d                   	pop    %ebp
  8004cc:	c3                   	ret    

008004cd <vprintfmt>:
// Main function to format and print a string.
void printfmt(void (*putch)(int, void*), void *putdat, const char *fmt, ...);

void
vprintfmt(void (*putch)(int, void*), void *putdat, const char *fmt, va_list ap)
{
  8004cd:	55                   	push   %ebp
  8004ce:	89 e5                	mov    %esp,%ebp
  8004d0:	57                   	push   %edi
  8004d1:	56                   	push   %esi
  8004d2:	53                   	push   %ebx
  8004d3:	83 ec 5c             	sub    $0x5c,%esp
  8004d6:	8b 7d 08             	mov    0x8(%ebp),%edi
  8004d9:	8b 75 0c             	mov    0xc(%ebp),%esi
  8004dc:	8b 5d 10             	mov    0x10(%ebp),%ebx
		case '#':
			altflag = 1;
			goto reswitch;

		process_precision:
			if (width < 0)
  8004df:	c7 45 c8 ff ff ff ff 	movl   $0xffffffff,-0x38(%ebp)
  8004e6:	eb 11                	jmp    8004f9 <vprintfmt+0x2c>
	int base, lflag, width, precision, altflag;
	char padc;

	while (1) {
		while ((ch = *(unsigned char *) fmt++) != '%') {
			if (ch == '\0')
  8004e8:	85 c0                	test   %eax,%eax
  8004ea:	0f 84 f9 03 00 00    	je     8008e9 <vprintfmt+0x41c>
				return;
			putch(ch, putdat);
  8004f0:	89 74 24 04          	mov    %esi,0x4(%esp)
  8004f4:	89 04 24             	mov    %eax,(%esp)
  8004f7:	ff d7                	call   *%edi
	unsigned long long num;
	int base, lflag, width, precision, altflag;
	char padc;

	while (1) {
		while ((ch = *(unsigned char *) fmt++) != '%') {
  8004f9:	0f b6 03             	movzbl (%ebx),%eax
  8004fc:	83 c3 01             	add    $0x1,%ebx
  8004ff:	83 f8 25             	cmp    $0x25,%eax
  800502:	75 e4                	jne    8004e8 <vprintfmt+0x1b>
  800504:	c6 45 d4 20          	movb   $0x20,-0x2c(%ebp)
  800508:	c7 45 d8 00 00 00 00 	movl   $0x0,-0x28(%ebp)
  80050f:	c7 45 d0 ff ff ff ff 	movl   $0xffffffff,-0x30(%ebp)
  800516:	c7 45 e4 ff ff ff ff 	movl   $0xffffffff,-0x1c(%ebp)
  80051d:	b9 00 00 00 00       	mov    $0x0,%ecx
  800522:	eb 06                	jmp    80052a <vprintfmt+0x5d>
  800524:	c6 45 d4 2d          	movb   $0x2d,-0x2c(%ebp)
  800528:	89 c3                	mov    %eax,%ebx
		width = -1;
		precision = -1;
		lflag = 0;
		altflag = 0;
	reswitch:
		switch (ch = *(unsigned char *) fmt++) {
  80052a:	0f b6 13             	movzbl (%ebx),%edx
  80052d:	0f b6 c2             	movzbl %dl,%eax
  800530:	89 45 e0             	mov    %eax,-0x20(%ebp)
  800533:	8d 43 01             	lea    0x1(%ebx),%eax
  800536:	83 ea 23             	sub    $0x23,%edx
  800539:	80 fa 55             	cmp    $0x55,%dl
  80053c:	0f 87 8a 03 00 00    	ja     8008cc <vprintfmt+0x3ff>
  800542:	0f b6 d2             	movzbl %dl,%edx
  800545:	ff 24 95 80 30 80 00 	jmp    *0x803080(,%edx,4)
  80054c:	c6 45 d4 30          	movb   $0x30,-0x2c(%ebp)
  800550:	eb d6                	jmp    800528 <vprintfmt+0x5b>
		case '6':
		case '7':
		case '8':
		case '9':
			for (precision = 0; ; ++fmt) {
				precision = precision * 10 + ch - '0';
  800552:	8b 55 e0             	mov    -0x20(%ebp),%edx
  800555:	83 ea 30             	sub    $0x30,%edx
  800558:	89 55 d0             	mov    %edx,-0x30(%ebp)
				ch = *fmt;
  80055b:	0f be 10             	movsbl (%eax),%edx
				if (ch < '0' || ch > '9')
  80055e:	8d 5a d0             	lea    -0x30(%edx),%ebx
  800561:	83 fb 09             	cmp    $0x9,%ebx
  800564:	77 54                	ja     8005ba <vprintfmt+0xed>
  800566:	89 4d e0             	mov    %ecx,-0x20(%ebp)
  800569:	8b 4d d0             	mov    -0x30(%ebp),%ecx
		case '5':
		case '6':
		case '7':
		case '8':
		case '9':
			for (precision = 0; ; ++fmt) {
  80056c:	83 c0 01             	add    $0x1,%eax
				precision = precision * 10 + ch - '0';
  80056f:	8d 0c 89             	lea    (%ecx,%ecx,4),%ecx
  800572:	8d 4c 4a d0          	lea    -0x30(%edx,%ecx,2),%ecx
				ch = *fmt;
  800576:	0f be 10             	movsbl (%eax),%edx
				if (ch < '0' || ch > '9')
  800579:	8d 5a d0             	lea    -0x30(%edx),%ebx
  80057c:	83 fb 09             	cmp    $0x9,%ebx
  80057f:	76 eb                	jbe    80056c <vprintfmt+0x9f>
  800581:	89 4d d0             	mov    %ecx,-0x30(%ebp)
  800584:	8b 4d e0             	mov    -0x20(%ebp),%ecx
  800587:	eb 31                	jmp    8005ba <vprintfmt+0xed>
					break;
			}
			goto process_precision;

		case '*':
			precision = va_arg(ap, int);
  800589:	8b 55 14             	mov    0x14(%ebp),%edx
  80058c:	8d 5a 04             	lea    0x4(%edx),%ebx
  80058f:	89 5d 14             	mov    %ebx,0x14(%ebp)
  800592:	8b 12                	mov    (%edx),%edx
  800594:	89 55 d0             	mov    %edx,-0x30(%ebp)
			goto process_precision;
  800597:	eb 21                	jmp    8005ba <vprintfmt+0xed>

		case '.':
			if (width < 0)
  800599:	83 7d e4 00          	cmpl   $0x0,-0x1c(%ebp)
  80059d:	ba 00 00 00 00       	mov    $0x0,%edx
  8005a2:	0f 49 55 e4          	cmovns -0x1c(%ebp),%edx
  8005a6:	89 55 e4             	mov    %edx,-0x1c(%ebp)
  8005a9:	e9 7a ff ff ff       	jmp    800528 <vprintfmt+0x5b>
  8005ae:	c7 45 d8 01 00 00 00 	movl   $0x1,-0x28(%ebp)
				width = 0;
			goto reswitch;

		case '#':
			altflag = 1;
			goto reswitch;
  8005b5:	e9 6e ff ff ff       	jmp    800528 <vprintfmt+0x5b>

		process_precision:
			if (width < 0)
  8005ba:	83 7d e4 00          	cmpl   $0x0,-0x1c(%ebp)
  8005be:	0f 89 64 ff ff ff    	jns    800528 <vprintfmt+0x5b>
  8005c4:	8b 55 d0             	mov    -0x30(%ebp),%edx
  8005c7:	89 55 e4             	mov    %edx,-0x1c(%ebp)
  8005ca:	8b 55 c8             	mov    -0x38(%ebp),%edx
  8005cd:	89 55 d0             	mov    %edx,-0x30(%ebp)
  8005d0:	e9 53 ff ff ff       	jmp    800528 <vprintfmt+0x5b>
				width = precision, precision = -1;
			goto reswitch;

		// long flag (doubled for long long)
		case 'l':
			lflag++;
  8005d5:	83 c1 01             	add    $0x1,%ecx
			goto reswitch;
  8005d8:	e9 4b ff ff ff       	jmp    800528 <vprintfmt+0x5b>
  8005dd:	89 45 cc             	mov    %eax,-0x34(%ebp)

		// character
		case 'c':
			putch(va_arg(ap, int), putdat);
  8005e0:	8b 45 14             	mov    0x14(%ebp),%eax
  8005e3:	8d 50 04             	lea    0x4(%eax),%edx
  8005e6:	89 55 14             	mov    %edx,0x14(%ebp)
  8005e9:	89 74 24 04          	mov    %esi,0x4(%esp)
  8005ed:	8b 00                	mov    (%eax),%eax
  8005ef:	89 04 24             	mov    %eax,(%esp)
  8005f2:	ff d7                	call   *%edi
  8005f4:	8b 5d cc             	mov    -0x34(%ebp),%ebx
			break;
  8005f7:	e9 fd fe ff ff       	jmp    8004f9 <vprintfmt+0x2c>
  8005fc:	89 45 cc             	mov    %eax,-0x34(%ebp)

		// error message
		case 'e':
			err = va_arg(ap, int);
  8005ff:	8b 45 14             	mov    0x14(%ebp),%eax
  800602:	8d 50 04             	lea    0x4(%eax),%edx
  800605:	89 55 14             	mov    %edx,0x14(%ebp)
  800608:	8b 00                	mov    (%eax),%eax
  80060a:	89 c2                	mov    %eax,%edx
  80060c:	c1 fa 1f             	sar    $0x1f,%edx
  80060f:	31 d0                	xor    %edx,%eax
  800611:	29 d0                	sub    %edx,%eax
			if (err < 0)
				err = -err;
			if (err > MAXERROR || (p = error_string[err]) == NULL)
  800613:	83 f8 12             	cmp    $0x12,%eax
  800616:	7f 0b                	jg     800623 <vprintfmt+0x156>
  800618:	8b 14 85 e0 31 80 00 	mov    0x8031e0(,%eax,4),%edx
  80061f:	85 d2                	test   %edx,%edx
  800621:	75 20                	jne    800643 <vprintfmt+0x176>
				printfmt(putch, putdat, "error %d", err);
  800623:	89 44 24 0c          	mov    %eax,0xc(%esp)
  800627:	c7 44 24 08 40 2f 80 	movl   $0x802f40,0x8(%esp)
  80062e:	00 
  80062f:	89 74 24 04          	mov    %esi,0x4(%esp)
  800633:	89 3c 24             	mov    %edi,(%esp)
  800636:	e8 36 03 00 00       	call   800971 <printfmt>
  80063b:	8b 5d cc             	mov    -0x34(%ebp),%ebx
		// error message
		case 'e':
			err = va_arg(ap, int);
			if (err < 0)
				err = -err;
			if (err > MAXERROR || (p = error_string[err]) == NULL)
  80063e:	e9 b6 fe ff ff       	jmp    8004f9 <vprintfmt+0x2c>
				printfmt(putch, putdat, "error %d", err);
			else
				printfmt(putch, putdat, "%s", p);
  800643:	89 54 24 0c          	mov    %edx,0xc(%esp)
  800647:	c7 44 24 08 f2 34 80 	movl   $0x8034f2,0x8(%esp)
  80064e:	00 
  80064f:	89 74 24 04          	mov    %esi,0x4(%esp)
  800653:	89 3c 24             	mov    %edi,(%esp)
  800656:	e8 16 03 00 00       	call   800971 <printfmt>
  80065b:	8b 5d cc             	mov    -0x34(%ebp),%ebx
  80065e:	e9 96 fe ff ff       	jmp    8004f9 <vprintfmt+0x2c>
  800663:	89 45 cc             	mov    %eax,-0x34(%ebp)
  800666:	89 c3                	mov    %eax,%ebx
  800668:	8b 4d d0             	mov    -0x30(%ebp),%ecx
  80066b:	8b 45 e4             	mov    -0x1c(%ebp),%eax
  80066e:	89 45 c4             	mov    %eax,-0x3c(%ebp)
			break;

		// string
		case 's':
			if ((p = va_arg(ap, char *)) == NULL)
  800671:	8b 45 14             	mov    0x14(%ebp),%eax
  800674:	8d 50 04             	lea    0x4(%eax),%edx
  800677:	89 55 14             	mov    %edx,0x14(%ebp)
  80067a:	8b 00                	mov    (%eax),%eax
  80067c:	89 45 e0             	mov    %eax,-0x20(%ebp)
  80067f:	85 c0                	test   %eax,%eax
  800681:	b8 49 2f 80 00       	mov    $0x802f49,%eax
  800686:	0f 45 45 e0          	cmovne -0x20(%ebp),%eax
  80068a:	89 45 e0             	mov    %eax,-0x20(%ebp)
				p = "(null)";
			if (width > 0 && padc != '-')
  80068d:	83 7d c4 00          	cmpl   $0x0,-0x3c(%ebp)
  800691:	7e 06                	jle    800699 <vprintfmt+0x1cc>
  800693:	80 7d d4 2d          	cmpb   $0x2d,-0x2c(%ebp)
  800697:	75 13                	jne    8006ac <vprintfmt+0x1df>
				for (width -= strnlen(p, precision); width > 0; width--)
					putch(padc, putdat);
			for (; (ch = *p++) != '\0' && (precision < 0 || --precision >= 0); width--)
  800699:	8b 55 e0             	mov    -0x20(%ebp),%edx
  80069c:	0f be 02             	movsbl (%edx),%eax
  80069f:	85 c0                	test   %eax,%eax
  8006a1:	0f 85 9b 00 00 00    	jne    800742 <vprintfmt+0x275>
  8006a7:	e9 88 00 00 00       	jmp    800734 <vprintfmt+0x267>
		// string
		case 's':
			if ((p = va_arg(ap, char *)) == NULL)
				p = "(null)";
			if (width > 0 && padc != '-')
				for (width -= strnlen(p, precision); width > 0; width--)
  8006ac:	89 4c 24 04          	mov    %ecx,0x4(%esp)
  8006b0:	8b 4d e0             	mov    -0x20(%ebp),%ecx
  8006b3:	89 0c 24             	mov    %ecx,(%esp)
  8006b6:	e8 00 03 00 00       	call   8009bb <strnlen>
  8006bb:	8b 55 c4             	mov    -0x3c(%ebp),%edx
  8006be:	29 c2                	sub    %eax,%edx
  8006c0:	89 55 e4             	mov    %edx,-0x1c(%ebp)
  8006c3:	85 d2                	test   %edx,%edx
  8006c5:	7e d2                	jle    800699 <vprintfmt+0x1cc>
					putch(padc, putdat);
  8006c7:	0f be 4d d4          	movsbl -0x2c(%ebp),%ecx
  8006cb:	89 4d d4             	mov    %ecx,-0x2c(%ebp)
  8006ce:	89 5d c4             	mov    %ebx,-0x3c(%ebp)
  8006d1:	89 d3                	mov    %edx,%ebx
  8006d3:	89 74 24 04          	mov    %esi,0x4(%esp)
  8006d7:	8b 45 d4             	mov    -0x2c(%ebp),%eax
  8006da:	89 04 24             	mov    %eax,(%esp)
  8006dd:	ff d7                	call   *%edi
		// string
		case 's':
			if ((p = va_arg(ap, char *)) == NULL)
				p = "(null)";
			if (width > 0 && padc != '-')
				for (width -= strnlen(p, precision); width > 0; width--)
  8006df:	83 eb 01             	sub    $0x1,%ebx
  8006e2:	85 db                	test   %ebx,%ebx
  8006e4:	7f ed                	jg     8006d3 <vprintfmt+0x206>
  8006e6:	8b 5d c4             	mov    -0x3c(%ebp),%ebx
  8006e9:	c7 45 e4 00 00 00 00 	movl   $0x0,-0x1c(%ebp)
  8006f0:	eb a7                	jmp    800699 <vprintfmt+0x1cc>
					putch(padc, putdat);
			for (; (ch = *p++) != '\0' && (precision < 0 || --precision >= 0); width--)
				if (altflag && (ch < ' ' || ch > '~'))
  8006f2:	83 7d d8 00          	cmpl   $0x0,-0x28(%ebp)
  8006f6:	74 1a                	je     800712 <vprintfmt+0x245>
  8006f8:	8d 50 e0             	lea    -0x20(%eax),%edx
  8006fb:	83 fa 5e             	cmp    $0x5e,%edx
  8006fe:	76 12                	jbe    800712 <vprintfmt+0x245>
					putch('?', putdat);
  800700:	89 7c 24 04          	mov    %edi,0x4(%esp)
  800704:	c7 04 24 3f 00 00 00 	movl   $0x3f,(%esp)
  80070b:	ff 55 e0             	call   *-0x20(%ebp)
				p = "(null)";
			if (width > 0 && padc != '-')
				for (width -= strnlen(p, precision); width > 0; width--)
					putch(padc, putdat);
			for (; (ch = *p++) != '\0' && (precision < 0 || --precision >= 0); width--)
				if (altflag && (ch < ' ' || ch > '~'))
  80070e:	66 90                	xchg   %ax,%ax
  800710:	eb 0a                	jmp    80071c <vprintfmt+0x24f>
					putch('?', putdat);
				else
					putch(ch, putdat);
  800712:	89 7c 24 04          	mov    %edi,0x4(%esp)
  800716:	89 04 24             	mov    %eax,(%esp)
  800719:	ff 55 e0             	call   *-0x20(%ebp)
			if ((p = va_arg(ap, char *)) == NULL)
				p = "(null)";
			if (width > 0 && padc != '-')
				for (width -= strnlen(p, precision); width > 0; width--)
					putch(padc, putdat);
			for (; (ch = *p++) != '\0' && (precision < 0 || --precision >= 0); width--)
  80071c:	83 6d e4 01          	subl   $0x1,-0x1c(%ebp)
  800720:	0f be 03             	movsbl (%ebx),%eax
  800723:	85 c0                	test   %eax,%eax
  800725:	74 05                	je     80072c <vprintfmt+0x25f>
  800727:	83 c3 01             	add    $0x1,%ebx
  80072a:	eb 29                	jmp    800755 <vprintfmt+0x288>
  80072c:	89 fe                	mov    %edi,%esi
  80072e:	8b 7d e0             	mov    -0x20(%ebp),%edi
  800731:	8b 5d d0             	mov    -0x30(%ebp),%ebx
				if (altflag && (ch < ' ' || ch > '~'))
					putch('?', putdat);
				else
					putch(ch, putdat);
			for (; width > 0; width--)
  800734:	83 7d e4 00          	cmpl   $0x0,-0x1c(%ebp)
  800738:	7f 2e                	jg     800768 <vprintfmt+0x29b>
  80073a:	8b 5d cc             	mov    -0x34(%ebp),%ebx
  80073d:	e9 b7 fd ff ff       	jmp    8004f9 <vprintfmt+0x2c>
			if ((p = va_arg(ap, char *)) == NULL)
				p = "(null)";
			if (width > 0 && padc != '-')
				for (width -= strnlen(p, precision); width > 0; width--)
					putch(padc, putdat);
			for (; (ch = *p++) != '\0' && (precision < 0 || --precision >= 0); width--)
  800742:	8b 55 e0             	mov    -0x20(%ebp),%edx
  800745:	83 c2 01             	add    $0x1,%edx
  800748:	89 7d e0             	mov    %edi,-0x20(%ebp)
  80074b:	89 f7                	mov    %esi,%edi
  80074d:	8b 75 d0             	mov    -0x30(%ebp),%esi
  800750:	89 5d d0             	mov    %ebx,-0x30(%ebp)
  800753:	89 d3                	mov    %edx,%ebx
  800755:	85 f6                	test   %esi,%esi
  800757:	78 99                	js     8006f2 <vprintfmt+0x225>
  800759:	83 ee 01             	sub    $0x1,%esi
  80075c:	79 94                	jns    8006f2 <vprintfmt+0x225>
  80075e:	89 fe                	mov    %edi,%esi
  800760:	8b 7d e0             	mov    -0x20(%ebp),%edi
  800763:	8b 5d d0             	mov    -0x30(%ebp),%ebx
  800766:	eb cc                	jmp    800734 <vprintfmt+0x267>
  800768:	89 5d d8             	mov    %ebx,-0x28(%ebp)
  80076b:	8b 5d e4             	mov    -0x1c(%ebp),%ebx
				if (altflag && (ch < ' ' || ch > '~'))
					putch('?', putdat);
				else
					putch(ch, putdat);
			for (; width > 0; width--)
				putch(' ', putdat);
  80076e:	89 74 24 04          	mov    %esi,0x4(%esp)
  800772:	c7 04 24 20 00 00 00 	movl   $0x20,(%esp)
  800779:	ff d7                	call   *%edi
			for (; (ch = *p++) != '\0' && (precision < 0 || --precision >= 0); width--)
				if (altflag && (ch < ' ' || ch > '~'))
					putch('?', putdat);
				else
					putch(ch, putdat);
			for (; width > 0; width--)
  80077b:	83 eb 01             	sub    $0x1,%ebx
  80077e:	85 db                	test   %ebx,%ebx
  800780:	7f ec                	jg     80076e <vprintfmt+0x2a1>
  800782:	8b 5d d8             	mov    -0x28(%ebp),%ebx
  800785:	e9 6f fd ff ff       	jmp    8004f9 <vprintfmt+0x2c>
  80078a:	89 45 cc             	mov    %eax,-0x34(%ebp)
// Same as getuint but signed - can't use getuint
// because of sign extension
static long long
getint(va_list *ap, int lflag)
{
	if (lflag >= 2)
  80078d:	83 f9 01             	cmp    $0x1,%ecx
  800790:	7e 16                	jle    8007a8 <vprintfmt+0x2db>
		return va_arg(*ap, long long);
  800792:	8b 45 14             	mov    0x14(%ebp),%eax
  800795:	8d 50 08             	lea    0x8(%eax),%edx
  800798:	89 55 14             	mov    %edx,0x14(%ebp)
  80079b:	8b 10                	mov    (%eax),%edx
  80079d:	8b 48 04             	mov    0x4(%eax),%ecx
  8007a0:	89 55 d8             	mov    %edx,-0x28(%ebp)
  8007a3:	89 4d dc             	mov    %ecx,-0x24(%ebp)
  8007a6:	eb 32                	jmp    8007da <vprintfmt+0x30d>
	else if (lflag)
  8007a8:	85 c9                	test   %ecx,%ecx
  8007aa:	74 18                	je     8007c4 <vprintfmt+0x2f7>
		return va_arg(*ap, long);
  8007ac:	8b 45 14             	mov    0x14(%ebp),%eax
  8007af:	8d 50 04             	lea    0x4(%eax),%edx
  8007b2:	89 55 14             	mov    %edx,0x14(%ebp)
  8007b5:	8b 00                	mov    (%eax),%eax
  8007b7:	89 45 d8             	mov    %eax,-0x28(%ebp)
  8007ba:	89 c1                	mov    %eax,%ecx
  8007bc:	c1 f9 1f             	sar    $0x1f,%ecx
  8007bf:	89 4d dc             	mov    %ecx,-0x24(%ebp)
  8007c2:	eb 16                	jmp    8007da <vprintfmt+0x30d>
	else
		return va_arg(*ap, int);
  8007c4:	8b 45 14             	mov    0x14(%ebp),%eax
  8007c7:	8d 50 04             	lea    0x4(%eax),%edx
  8007ca:	89 55 14             	mov    %edx,0x14(%ebp)
  8007cd:	8b 00                	mov    (%eax),%eax
  8007cf:	89 45 d8             	mov    %eax,-0x28(%ebp)
  8007d2:	89 c2                	mov    %eax,%edx
  8007d4:	c1 fa 1f             	sar    $0x1f,%edx
  8007d7:	89 55 dc             	mov    %edx,-0x24(%ebp)
				putch(' ', putdat);
			break;

		// (signed) decimal
		case 'd':
			num = getint(&ap, lflag);
  8007da:	8b 4d d8             	mov    -0x28(%ebp),%ecx
  8007dd:	8b 5d dc             	mov    -0x24(%ebp),%ebx
  8007e0:	b8 0a 00 00 00       	mov    $0xa,%eax
			if ((long long) num < 0) {
  8007e5:	83 7d dc 00          	cmpl   $0x0,-0x24(%ebp)
  8007e9:	0f 89 9b 00 00 00    	jns    80088a <vprintfmt+0x3bd>
				putch('-', putdat);
  8007ef:	89 74 24 04          	mov    %esi,0x4(%esp)
  8007f3:	c7 04 24 2d 00 00 00 	movl   $0x2d,(%esp)
  8007fa:	ff d7                	call   *%edi
				num = -(long long) num;
  8007fc:	8b 4d d8             	mov    -0x28(%ebp),%ecx
  8007ff:	8b 5d dc             	mov    -0x24(%ebp),%ebx
  800802:	f7 d9                	neg    %ecx
  800804:	83 d3 00             	adc    $0x0,%ebx
  800807:	f7 db                	neg    %ebx
  800809:	b8 0a 00 00 00       	mov    $0xa,%eax
  80080e:	eb 7a                	jmp    80088a <vprintfmt+0x3bd>
  800810:	89 45 cc             	mov    %eax,-0x34(%ebp)
			base = 10;
			goto number;

		// unsigned decimal
		case 'u':
			num = getuint(&ap, lflag);
  800813:	89 ca                	mov    %ecx,%edx
  800815:	8d 45 14             	lea    0x14(%ebp),%eax
  800818:	e8 59 fc ff ff       	call   800476 <getuint>
  80081d:	89 c1                	mov    %eax,%ecx
  80081f:	89 d3                	mov    %edx,%ebx
  800821:	b8 0a 00 00 00       	mov    $0xa,%eax
			base = 10;
			goto number;
  800826:	eb 62                	jmp    80088a <vprintfmt+0x3bd>
  800828:	89 45 cc             	mov    %eax,-0x34(%ebp)

		// (unsigned) octal
		case 'o':
			num = getuint(&ap, lflag);
  80082b:	89 ca                	mov    %ecx,%edx
  80082d:	8d 45 14             	lea    0x14(%ebp),%eax
  800830:	e8 41 fc ff ff       	call   800476 <getuint>
  800835:	89 c1                	mov    %eax,%ecx
  800837:	89 d3                	mov    %edx,%ebx
  800839:	b8 08 00 00 00       	mov    $0x8,%eax
			base = 8;
			goto number;
  80083e:	eb 4a                	jmp    80088a <vprintfmt+0x3bd>
  800840:	89 45 cc             	mov    %eax,-0x34(%ebp)
			break;
			**/

		// pointer
		case 'p':
			putch('0', putdat);
  800843:	89 74 24 04          	mov    %esi,0x4(%esp)
  800847:	c7 04 24 30 00 00 00 	movl   $0x30,(%esp)
  80084e:	ff d7                	call   *%edi
			putch('x', putdat);
  800850:	89 74 24 04          	mov    %esi,0x4(%esp)
  800854:	c7 04 24 78 00 00 00 	movl   $0x78,(%esp)
  80085b:	ff d7                	call   *%edi
			num = (unsigned long long)
  80085d:	8b 45 14             	mov    0x14(%ebp),%eax
  800860:	8d 50 04             	lea    0x4(%eax),%edx
  800863:	89 55 14             	mov    %edx,0x14(%ebp)
  800866:	8b 08                	mov    (%eax),%ecx
  800868:	bb 00 00 00 00       	mov    $0x0,%ebx
  80086d:	b8 10 00 00 00       	mov    $0x10,%eax
				(uintptr_t) va_arg(ap, void *);
			base = 16;
			goto number;
  800872:	eb 16                	jmp    80088a <vprintfmt+0x3bd>
  800874:	89 45 cc             	mov    %eax,-0x34(%ebp)

		// (unsigned) hexadecimal
		case 'x':
			num = getuint(&ap, lflag);
  800877:	89 ca                	mov    %ecx,%edx
  800879:	8d 45 14             	lea    0x14(%ebp),%eax
  80087c:	e8 f5 fb ff ff       	call   800476 <getuint>
  800881:	89 c1                	mov    %eax,%ecx
  800883:	89 d3                	mov    %edx,%ebx
  800885:	b8 10 00 00 00       	mov    $0x10,%eax
			base = 16;
		number:
			printnum(putch, putdat, num, base, width, padc);
  80088a:	0f be 55 d4          	movsbl -0x2c(%ebp),%edx
  80088e:	89 54 24 10          	mov    %edx,0x10(%esp)
  800892:	8b 55 e4             	mov    -0x1c(%ebp),%edx
  800895:	89 54 24 0c          	mov    %edx,0xc(%esp)
  800899:	89 44 24 08          	mov    %eax,0x8(%esp)
  80089d:	89 0c 24             	mov    %ecx,(%esp)
  8008a0:	89 5c 24 04          	mov    %ebx,0x4(%esp)
  8008a4:	89 f2                	mov    %esi,%edx
  8008a6:	89 f8                	mov    %edi,%eax
  8008a8:	e8 d3 fa ff ff       	call   800380 <printnum>
  8008ad:	8b 5d cc             	mov    -0x34(%ebp),%ebx
			break;
  8008b0:	e9 44 fc ff ff       	jmp    8004f9 <vprintfmt+0x2c>
  8008b5:	89 45 cc             	mov    %eax,-0x34(%ebp)
  8008b8:	8b 55 e0             	mov    -0x20(%ebp),%edx

		// escaped '%' character
		case '%':
			putch(ch, putdat);
  8008bb:	89 74 24 04          	mov    %esi,0x4(%esp)
  8008bf:	89 14 24             	mov    %edx,(%esp)
  8008c2:	ff d7                	call   *%edi
  8008c4:	8b 5d cc             	mov    -0x34(%ebp),%ebx
			break;
  8008c7:	e9 2d fc ff ff       	jmp    8004f9 <vprintfmt+0x2c>
			
		// unrecognized escape sequence - just print it literally
		default:
			putch('%', putdat);
  8008cc:	89 74 24 04          	mov    %esi,0x4(%esp)
  8008d0:	c7 04 24 25 00 00 00 	movl   $0x25,(%esp)
  8008d7:	ff d7                	call   *%edi
			for (fmt--; fmt[-1] != '%'; fmt--)
  8008d9:	8d 43 ff             	lea    -0x1(%ebx),%eax
  8008dc:	80 38 25             	cmpb   $0x25,(%eax)
  8008df:	0f 84 14 fc ff ff    	je     8004f9 <vprintfmt+0x2c>
  8008e5:	89 c3                	mov    %eax,%ebx
  8008e7:	eb f0                	jmp    8008d9 <vprintfmt+0x40c>
				/* do nothing */;
			break;
		}
	}
}
  8008e9:	83 c4 5c             	add    $0x5c,%esp
  8008ec:	5b                   	pop    %ebx
  8008ed:	5e                   	pop    %esi
  8008ee:	5f                   	pop    %edi
  8008ef:	5d                   	pop    %ebp
  8008f0:	c3                   	ret    

008008f1 <vsnprintf>:
		*b->buf++ = ch;
}

int
vsnprintf(char *buf, int n, const char *fmt, va_list ap)
{
  8008f1:	55                   	push   %ebp
  8008f2:	89 e5                	mov    %esp,%ebp
  8008f4:	83 ec 28             	sub    $0x28,%esp
  8008f7:	8b 45 08             	mov    0x8(%ebp),%eax
  8008fa:	8b 55 0c             	mov    0xc(%ebp),%edx
	struct sprintbuf b = {buf, buf+n-1, 0};

	if (buf == NULL || n < 1)
  8008fd:	85 c0                	test   %eax,%eax
  8008ff:	74 04                	je     800905 <vsnprintf+0x14>
  800901:	85 d2                	test   %edx,%edx
  800903:	7f 07                	jg     80090c <vsnprintf+0x1b>
  800905:	b8 fd ff ff ff       	mov    $0xfffffffd,%eax
  80090a:	eb 3b                	jmp    800947 <vsnprintf+0x56>
}

int
vsnprintf(char *buf, int n, const char *fmt, va_list ap)
{
	struct sprintbuf b = {buf, buf+n-1, 0};
  80090c:	89 45 ec             	mov    %eax,-0x14(%ebp)
  80090f:	8d 44 10 ff          	lea    -0x1(%eax,%edx,1),%eax
  800913:	89 45 f0             	mov    %eax,-0x10(%ebp)
  800916:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)

	if (buf == NULL || n < 1)
		return -E_INVAL;

	// print the string to the buffer
	vprintfmt((void*)sprintputch, &b, fmt, ap);
  80091d:	8b 45 14             	mov    0x14(%ebp),%eax
  800920:	89 44 24 0c          	mov    %eax,0xc(%esp)
  800924:	8b 45 10             	mov    0x10(%ebp),%eax
  800927:	89 44 24 08          	mov    %eax,0x8(%esp)
  80092b:	8d 45 ec             	lea    -0x14(%ebp),%eax
  80092e:	89 44 24 04          	mov    %eax,0x4(%esp)
  800932:	c7 04 24 b0 04 80 00 	movl   $0x8004b0,(%esp)
  800939:	e8 8f fb ff ff       	call   8004cd <vprintfmt>

	// null terminate the buffer
	*b.buf = '\0';
  80093e:	8b 45 ec             	mov    -0x14(%ebp),%eax
  800941:	c6 00 00             	movb   $0x0,(%eax)

	return b.cnt;
  800944:	8b 45 f4             	mov    -0xc(%ebp),%eax
}
  800947:	c9                   	leave  
  800948:	c3                   	ret    

00800949 <snprintf>:

int
snprintf(char *buf, int n, const char *fmt, ...)
{
  800949:	55                   	push   %ebp
  80094a:	89 e5                	mov    %esp,%ebp
  80094c:	83 ec 18             	sub    $0x18,%esp

	return b.cnt;
}

int
snprintf(char *buf, int n, const char *fmt, ...)
  80094f:	8d 45 14             	lea    0x14(%ebp),%eax
{
	va_list ap;
	int rc;

	va_start(ap, fmt);
	rc = vsnprintf(buf, n, fmt, ap);
  800952:	89 44 24 0c          	mov    %eax,0xc(%esp)
  800956:	8b 45 10             	mov    0x10(%ebp),%eax
  800959:	89 44 24 08          	mov    %eax,0x8(%esp)
  80095d:	8b 45 0c             	mov    0xc(%ebp),%eax
  800960:	89 44 24 04          	mov    %eax,0x4(%esp)
  800964:	8b 45 08             	mov    0x8(%ebp),%eax
  800967:	89 04 24             	mov    %eax,(%esp)
  80096a:	e8 82 ff ff ff       	call   8008f1 <vsnprintf>
	va_end(ap);

	return rc;
}
  80096f:	c9                   	leave  
  800970:	c3                   	ret    

00800971 <printfmt>:
	}
}

void
printfmt(void (*putch)(int, void*), void *putdat, const char *fmt, ...)
{
  800971:	55                   	push   %ebp
  800972:	89 e5                	mov    %esp,%ebp
  800974:	83 ec 18             	sub    $0x18,%esp
		}
	}
}

void
printfmt(void (*putch)(int, void*), void *putdat, const char *fmt, ...)
  800977:	8d 45 14             	lea    0x14(%ebp),%eax
{
	va_list ap;

	va_start(ap, fmt);
	vprintfmt(putch, putdat, fmt, ap);
  80097a:	89 44 24 0c          	mov    %eax,0xc(%esp)
  80097e:	8b 45 10             	mov    0x10(%ebp),%eax
  800981:	89 44 24 08          	mov    %eax,0x8(%esp)
  800985:	8b 45 0c             	mov    0xc(%ebp),%eax
  800988:	89 44 24 04          	mov    %eax,0x4(%esp)
  80098c:	8b 45 08             	mov    0x8(%ebp),%eax
  80098f:	89 04 24             	mov    %eax,(%esp)
  800992:	e8 36 fb ff ff       	call   8004cd <vprintfmt>
	va_end(ap);
}
  800997:	c9                   	leave  
  800998:	c3                   	ret    
  800999:	00 00                	add    %al,(%eax)
  80099b:	00 00                	add    %al,(%eax)
  80099d:	00 00                	add    %al,(%eax)
	...

008009a0 <strlen>:
// Primespipe runs 3x faster this way.
#define ASM 1

int
strlen(const char *s)
{
  8009a0:	55                   	push   %ebp
  8009a1:	89 e5                	mov    %esp,%ebp
  8009a3:	8b 55 08             	mov    0x8(%ebp),%edx
	int n;

	for (n = 0; *s != '\0'; s++)
  8009a6:	b8 00 00 00 00       	mov    $0x0,%eax
  8009ab:	80 3a 00             	cmpb   $0x0,(%edx)
  8009ae:	74 09                	je     8009b9 <strlen+0x19>
		n++;
  8009b0:	83 c0 01             	add    $0x1,%eax
int
strlen(const char *s)
{
	int n;

	for (n = 0; *s != '\0'; s++)
  8009b3:	80 3c 02 00          	cmpb   $0x0,(%edx,%eax,1)
  8009b7:	75 f7                	jne    8009b0 <strlen+0x10>
		n++;
	return n;
}
  8009b9:	5d                   	pop    %ebp
  8009ba:	c3                   	ret    

008009bb <strnlen>:

int
strnlen(const char *s, size_t size)
{
  8009bb:	55                   	push   %ebp
  8009bc:	89 e5                	mov    %esp,%ebp
  8009be:	53                   	push   %ebx
  8009bf:	8b 5d 08             	mov    0x8(%ebp),%ebx
  8009c2:	8b 4d 0c             	mov    0xc(%ebp),%ecx
	int n;

	for (n = 0; size > 0 && *s != '\0'; s++, size--)
  8009c5:	85 c9                	test   %ecx,%ecx
  8009c7:	74 19                	je     8009e2 <strnlen+0x27>
  8009c9:	80 3b 00             	cmpb   $0x0,(%ebx)
  8009cc:	74 14                	je     8009e2 <strnlen+0x27>
  8009ce:	b8 00 00 00 00       	mov    $0x0,%eax
		n++;
  8009d3:	83 c0 01             	add    $0x1,%eax
int
strnlen(const char *s, size_t size)
{
	int n;

	for (n = 0; size > 0 && *s != '\0'; s++, size--)
  8009d6:	39 c8                	cmp    %ecx,%eax
  8009d8:	74 0d                	je     8009e7 <strnlen+0x2c>
  8009da:	80 3c 03 00          	cmpb   $0x0,(%ebx,%eax,1)
  8009de:	75 f3                	jne    8009d3 <strnlen+0x18>
  8009e0:	eb 05                	jmp    8009e7 <strnlen+0x2c>
  8009e2:	b8 00 00 00 00       	mov    $0x0,%eax
		n++;
	return n;
}
  8009e7:	5b                   	pop    %ebx
  8009e8:	5d                   	pop    %ebp
  8009e9:	c3                   	ret    

008009ea <strcpy>:

char *
strcpy(char *dst, const char *src)
{
  8009ea:	55                   	push   %ebp
  8009eb:	89 e5                	mov    %esp,%ebp
  8009ed:	53                   	push   %ebx
  8009ee:	8b 45 08             	mov    0x8(%ebp),%eax
  8009f1:	8b 5d 0c             	mov    0xc(%ebp),%ebx
  8009f4:	ba 00 00 00 00       	mov    $0x0,%edx
	char *ret;

	ret = dst;
	while ((*dst++ = *src++) != '\0')
  8009f9:	0f b6 0c 13          	movzbl (%ebx,%edx,1),%ecx
  8009fd:	88 0c 10             	mov    %cl,(%eax,%edx,1)
  800a00:	83 c2 01             	add    $0x1,%edx
  800a03:	84 c9                	test   %cl,%cl
  800a05:	75 f2                	jne    8009f9 <strcpy+0xf>
		/* do nothing */;
	return ret;
}
  800a07:	5b                   	pop    %ebx
  800a08:	5d                   	pop    %ebp
  800a09:	c3                   	ret    

00800a0a <strncpy>:

char *
strncpy(char *dst, const char *src, size_t size) {
  800a0a:	55                   	push   %ebp
  800a0b:	89 e5                	mov    %esp,%ebp
  800a0d:	56                   	push   %esi
  800a0e:	53                   	push   %ebx
  800a0f:	8b 45 08             	mov    0x8(%ebp),%eax
  800a12:	8b 55 0c             	mov    0xc(%ebp),%edx
  800a15:	8b 75 10             	mov    0x10(%ebp),%esi
	size_t i;
	char *ret;

	ret = dst;
	for (i = 0; i < size; i++) {
  800a18:	85 f6                	test   %esi,%esi
  800a1a:	74 18                	je     800a34 <strncpy+0x2a>
  800a1c:	b9 00 00 00 00       	mov    $0x0,%ecx
		*dst++ = *src;
  800a21:	0f b6 1a             	movzbl (%edx),%ebx
  800a24:	88 1c 08             	mov    %bl,(%eax,%ecx,1)
		// If strlen(src) < size, null-pad 'dst' out to 'size' chars
		if (*src != '\0')
			src++;
  800a27:	80 3a 01             	cmpb   $0x1,(%edx)
  800a2a:	83 da ff             	sbb    $0xffffffff,%edx
strncpy(char *dst, const char *src, size_t size) {
	size_t i;
	char *ret;

	ret = dst;
	for (i = 0; i < size; i++) {
  800a2d:	83 c1 01             	add    $0x1,%ecx
  800a30:	39 ce                	cmp    %ecx,%esi
  800a32:	77 ed                	ja     800a21 <strncpy+0x17>
		// If strlen(src) < size, null-pad 'dst' out to 'size' chars
		if (*src != '\0')
			src++;
	}
	return ret;
}
  800a34:	5b                   	pop    %ebx
  800a35:	5e                   	pop    %esi
  800a36:	5d                   	pop    %ebp
  800a37:	c3                   	ret    

00800a38 <strlcpy>:

size_t
strlcpy(char *dst, const char *src, size_t size)
{
  800a38:	55                   	push   %ebp
  800a39:	89 e5                	mov    %esp,%ebp
  800a3b:	56                   	push   %esi
  800a3c:	53                   	push   %ebx
  800a3d:	8b 75 08             	mov    0x8(%ebp),%esi
  800a40:	8b 55 0c             	mov    0xc(%ebp),%edx
  800a43:	8b 4d 10             	mov    0x10(%ebp),%ecx
	char *dst_in;

	dst_in = dst;
	if (size > 0) {
  800a46:	89 f0                	mov    %esi,%eax
  800a48:	85 c9                	test   %ecx,%ecx
  800a4a:	74 27                	je     800a73 <strlcpy+0x3b>
		while (--size > 0 && *src != '\0')
  800a4c:	83 e9 01             	sub    $0x1,%ecx
  800a4f:	74 1d                	je     800a6e <strlcpy+0x36>
  800a51:	0f b6 1a             	movzbl (%edx),%ebx
  800a54:	84 db                	test   %bl,%bl
  800a56:	74 16                	je     800a6e <strlcpy+0x36>
			*dst++ = *src++;
  800a58:	88 18                	mov    %bl,(%eax)
  800a5a:	83 c0 01             	add    $0x1,%eax
{
	char *dst_in;

	dst_in = dst;
	if (size > 0) {
		while (--size > 0 && *src != '\0')
  800a5d:	83 e9 01             	sub    $0x1,%ecx
  800a60:	74 0e                	je     800a70 <strlcpy+0x38>
			*dst++ = *src++;
  800a62:	83 c2 01             	add    $0x1,%edx
{
	char *dst_in;

	dst_in = dst;
	if (size > 0) {
		while (--size > 0 && *src != '\0')
  800a65:	0f b6 1a             	movzbl (%edx),%ebx
  800a68:	84 db                	test   %bl,%bl
  800a6a:	75 ec                	jne    800a58 <strlcpy+0x20>
  800a6c:	eb 02                	jmp    800a70 <strlcpy+0x38>
  800a6e:	89 f0                	mov    %esi,%eax
			*dst++ = *src++;
		*dst = '\0';
  800a70:	c6 00 00             	movb   $0x0,(%eax)
  800a73:	29 f0                	sub    %esi,%eax
	}
	return dst - dst_in;
}
  800a75:	5b                   	pop    %ebx
  800a76:	5e                   	pop    %esi
  800a77:	5d                   	pop    %ebp
  800a78:	c3                   	ret    

00800a79 <strcmp>:

int
strcmp(const char *p, const char *q)
{
  800a79:	55                   	push   %ebp
  800a7a:	89 e5                	mov    %esp,%ebp
  800a7c:	8b 4d 08             	mov    0x8(%ebp),%ecx
  800a7f:	8b 55 0c             	mov    0xc(%ebp),%edx
	while (*p && *p == *q)
  800a82:	0f b6 01             	movzbl (%ecx),%eax
  800a85:	84 c0                	test   %al,%al
  800a87:	74 15                	je     800a9e <strcmp+0x25>
  800a89:	3a 02                	cmp    (%edx),%al
  800a8b:	75 11                	jne    800a9e <strcmp+0x25>
		p++, q++;
  800a8d:	83 c1 01             	add    $0x1,%ecx
  800a90:	83 c2 01             	add    $0x1,%edx
}

int
strcmp(const char *p, const char *q)
{
	while (*p && *p == *q)
  800a93:	0f b6 01             	movzbl (%ecx),%eax
  800a96:	84 c0                	test   %al,%al
  800a98:	74 04                	je     800a9e <strcmp+0x25>
  800a9a:	3a 02                	cmp    (%edx),%al
  800a9c:	74 ef                	je     800a8d <strcmp+0x14>
  800a9e:	0f b6 c0             	movzbl %al,%eax
  800aa1:	0f b6 12             	movzbl (%edx),%edx
  800aa4:	29 d0                	sub    %edx,%eax
		p++, q++;
	return (int) ((unsigned char) *p - (unsigned char) *q);
}
  800aa6:	5d                   	pop    %ebp
  800aa7:	c3                   	ret    

00800aa8 <strncmp>:

int
strncmp(const char *p, const char *q, size_t n)
{
  800aa8:	55                   	push   %ebp
  800aa9:	89 e5                	mov    %esp,%ebp
  800aab:	53                   	push   %ebx
  800aac:	8b 55 08             	mov    0x8(%ebp),%edx
  800aaf:	8b 4d 0c             	mov    0xc(%ebp),%ecx
  800ab2:	8b 45 10             	mov    0x10(%ebp),%eax
	while (n > 0 && *p && *p == *q)
  800ab5:	85 c0                	test   %eax,%eax
  800ab7:	74 23                	je     800adc <strncmp+0x34>
  800ab9:	0f b6 1a             	movzbl (%edx),%ebx
  800abc:	84 db                	test   %bl,%bl
  800abe:	74 24                	je     800ae4 <strncmp+0x3c>
  800ac0:	3a 19                	cmp    (%ecx),%bl
  800ac2:	75 20                	jne    800ae4 <strncmp+0x3c>
  800ac4:	83 e8 01             	sub    $0x1,%eax
  800ac7:	74 13                	je     800adc <strncmp+0x34>
		n--, p++, q++;
  800ac9:	83 c2 01             	add    $0x1,%edx
  800acc:	83 c1 01             	add    $0x1,%ecx
}

int
strncmp(const char *p, const char *q, size_t n)
{
	while (n > 0 && *p && *p == *q)
  800acf:	0f b6 1a             	movzbl (%edx),%ebx
  800ad2:	84 db                	test   %bl,%bl
  800ad4:	74 0e                	je     800ae4 <strncmp+0x3c>
  800ad6:	3a 19                	cmp    (%ecx),%bl
  800ad8:	74 ea                	je     800ac4 <strncmp+0x1c>
  800ada:	eb 08                	jmp    800ae4 <strncmp+0x3c>
  800adc:	b8 00 00 00 00       	mov    $0x0,%eax
		n--, p++, q++;
	if (n == 0)
		return 0;
	else
		return (int) ((unsigned char) *p - (unsigned char) *q);
}
  800ae1:	5b                   	pop    %ebx
  800ae2:	5d                   	pop    %ebp
  800ae3:	c3                   	ret    
	while (n > 0 && *p && *p == *q)
		n--, p++, q++;
	if (n == 0)
		return 0;
	else
		return (int) ((unsigned char) *p - (unsigned char) *q);
  800ae4:	0f b6 02             	movzbl (%edx),%eax
  800ae7:	0f b6 11             	movzbl (%ecx),%edx
  800aea:	29 d0                	sub    %edx,%eax
  800aec:	eb f3                	jmp    800ae1 <strncmp+0x39>

00800aee <strchr>:

// Return a pointer to the first occurrence of 'c' in 's',
// or a null pointer if the string has no 'c'.
char *
strchr(const char *s, char c)
{
  800aee:	55                   	push   %ebp
  800aef:	89 e5                	mov    %esp,%ebp
  800af1:	8b 45 08             	mov    0x8(%ebp),%eax
  800af4:	0f b6 4d 0c          	movzbl 0xc(%ebp),%ecx
	for (; *s; s++)
  800af8:	0f b6 10             	movzbl (%eax),%edx
  800afb:	84 d2                	test   %dl,%dl
  800afd:	74 15                	je     800b14 <strchr+0x26>
		if (*s == c)
  800aff:	38 ca                	cmp    %cl,%dl
  800b01:	75 07                	jne    800b0a <strchr+0x1c>
  800b03:	eb 14                	jmp    800b19 <strchr+0x2b>
  800b05:	38 ca                	cmp    %cl,%dl
  800b07:	90                   	nop
  800b08:	74 0f                	je     800b19 <strchr+0x2b>
// Return a pointer to the first occurrence of 'c' in 's',
// or a null pointer if the string has no 'c'.
char *
strchr(const char *s, char c)
{
	for (; *s; s++)
  800b0a:	83 c0 01             	add    $0x1,%eax
  800b0d:	0f b6 10             	movzbl (%eax),%edx
  800b10:	84 d2                	test   %dl,%dl
  800b12:	75 f1                	jne    800b05 <strchr+0x17>
  800b14:	b8 00 00 00 00       	mov    $0x0,%eax
		if (*s == c)
			return (char *) s;
	return 0;
}
  800b19:	5d                   	pop    %ebp
  800b1a:	c3                   	ret    

00800b1b <strfind>:

// Return a pointer to the first occurrence of 'c' in 's',
// or a pointer to the string-ending null character if the string has no 'c'.
char *
strfind(const char *s, char c)
{
  800b1b:	55                   	push   %ebp
  800b1c:	89 e5                	mov    %esp,%ebp
  800b1e:	8b 45 08             	mov    0x8(%ebp),%eax
  800b21:	0f b6 4d 0c          	movzbl 0xc(%ebp),%ecx
	for (; *s; s++)
  800b25:	0f b6 10             	movzbl (%eax),%edx
  800b28:	84 d2                	test   %dl,%dl
  800b2a:	74 18                	je     800b44 <strfind+0x29>
		if (*s == c)
  800b2c:	38 ca                	cmp    %cl,%dl
  800b2e:	75 0a                	jne    800b3a <strfind+0x1f>
  800b30:	eb 12                	jmp    800b44 <strfind+0x29>
  800b32:	38 ca                	cmp    %cl,%dl
  800b34:	8d 74 26 00          	lea    0x0(%esi,%eiz,1),%esi
  800b38:	74 0a                	je     800b44 <strfind+0x29>
// Return a pointer to the first occurrence of 'c' in 's',
// or a pointer to the string-ending null character if the string has no 'c'.
char *
strfind(const char *s, char c)
{
	for (; *s; s++)
  800b3a:	83 c0 01             	add    $0x1,%eax
  800b3d:	0f b6 10             	movzbl (%eax),%edx
  800b40:	84 d2                	test   %dl,%dl
  800b42:	75 ee                	jne    800b32 <strfind+0x17>
		if (*s == c)
			break;
	return (char *) s;
}
  800b44:	5d                   	pop    %ebp
  800b45:	c3                   	ret    

00800b46 <memset>:

#if ASM
void *
memset(void *v, int c, size_t n)
{
  800b46:	55                   	push   %ebp
  800b47:	89 e5                	mov    %esp,%ebp
  800b49:	83 ec 0c             	sub    $0xc,%esp
  800b4c:	89 1c 24             	mov    %ebx,(%esp)
  800b4f:	89 74 24 04          	mov    %esi,0x4(%esp)
  800b53:	89 7c 24 08          	mov    %edi,0x8(%esp)
  800b57:	8b 7d 08             	mov    0x8(%ebp),%edi
  800b5a:	8b 45 0c             	mov    0xc(%ebp),%eax
  800b5d:	8b 4d 10             	mov    0x10(%ebp),%ecx
	char *p;

	if (n == 0)
  800b60:	85 c9                	test   %ecx,%ecx
  800b62:	74 30                	je     800b94 <memset+0x4e>
		return v;
	if ((int)v%4 == 0 && n%4 == 0) {
  800b64:	f7 c7 03 00 00 00    	test   $0x3,%edi
  800b6a:	75 25                	jne    800b91 <memset+0x4b>
  800b6c:	f6 c1 03             	test   $0x3,%cl
  800b6f:	75 20                	jne    800b91 <memset+0x4b>
		c &= 0xFF;
  800b71:	0f b6 d0             	movzbl %al,%edx
		c = (c<<24)|(c<<16)|(c<<8)|c;
  800b74:	89 d3                	mov    %edx,%ebx
  800b76:	c1 e3 08             	shl    $0x8,%ebx
  800b79:	89 d6                	mov    %edx,%esi
  800b7b:	c1 e6 18             	shl    $0x18,%esi
  800b7e:	89 d0                	mov    %edx,%eax
  800b80:	c1 e0 10             	shl    $0x10,%eax
  800b83:	09 f0                	or     %esi,%eax
  800b85:	09 d0                	or     %edx,%eax
		asm volatile("cld; rep stosl\n"
  800b87:	09 d8                	or     %ebx,%eax
  800b89:	c1 e9 02             	shr    $0x2,%ecx
  800b8c:	fc                   	cld    
  800b8d:	f3 ab                	rep stos %eax,%es:(%edi)
{
	char *p;

	if (n == 0)
		return v;
	if ((int)v%4 == 0 && n%4 == 0) {
  800b8f:	eb 03                	jmp    800b94 <memset+0x4e>
		c = (c<<24)|(c<<16)|(c<<8)|c;
		asm volatile("cld; rep stosl\n"
			:: "D" (v), "a" (c), "c" (n/4)
			: "cc", "memory");
	} else
		asm volatile("cld; rep stosb\n"
  800b91:	fc                   	cld    
  800b92:	f3 aa                	rep stos %al,%es:(%edi)
			:: "D" (v), "a" (c), "c" (n)
			: "cc", "memory");
	return v;
}
  800b94:	89 f8                	mov    %edi,%eax
  800b96:	8b 1c 24             	mov    (%esp),%ebx
  800b99:	8b 74 24 04          	mov    0x4(%esp),%esi
  800b9d:	8b 7c 24 08          	mov    0x8(%esp),%edi
  800ba1:	89 ec                	mov    %ebp,%esp
  800ba3:	5d                   	pop    %ebp
  800ba4:	c3                   	ret    

00800ba5 <memmove>:

void *
memmove(void *dst, const void *src, size_t n)
{
  800ba5:	55                   	push   %ebp
  800ba6:	89 e5                	mov    %esp,%ebp
  800ba8:	83 ec 08             	sub    $0x8,%esp
  800bab:	89 34 24             	mov    %esi,(%esp)
  800bae:	89 7c 24 04          	mov    %edi,0x4(%esp)
  800bb2:	8b 45 08             	mov    0x8(%ebp),%eax
  800bb5:	8b 4d 10             	mov    0x10(%ebp),%ecx
	const char *s;
	char *d;
	
	s = src;
  800bb8:	8b 75 0c             	mov    0xc(%ebp),%esi
	d = dst;
  800bbb:	89 c7                	mov    %eax,%edi
	if (s < d && s + n > d) {
  800bbd:	39 c6                	cmp    %eax,%esi
  800bbf:	73 35                	jae    800bf6 <memmove+0x51>
  800bc1:	8d 14 0e             	lea    (%esi,%ecx,1),%edx
  800bc4:	39 d0                	cmp    %edx,%eax
  800bc6:	73 2e                	jae    800bf6 <memmove+0x51>
		s += n;
		d += n;
  800bc8:	01 cf                	add    %ecx,%edi
		if ((int)s%4 == 0 && (int)d%4 == 0 && n%4 == 0)
  800bca:	f6 c2 03             	test   $0x3,%dl
  800bcd:	75 1b                	jne    800bea <memmove+0x45>
  800bcf:	f7 c7 03 00 00 00    	test   $0x3,%edi
  800bd5:	75 13                	jne    800bea <memmove+0x45>
  800bd7:	f6 c1 03             	test   $0x3,%cl
  800bda:	75 0e                	jne    800bea <memmove+0x45>
			asm volatile("std; rep movsl\n"
  800bdc:	83 ef 04             	sub    $0x4,%edi
  800bdf:	8d 72 fc             	lea    -0x4(%edx),%esi
  800be2:	c1 e9 02             	shr    $0x2,%ecx
  800be5:	fd                   	std    
  800be6:	f3 a5                	rep movsl %ds:(%esi),%es:(%edi)
	s = src;
	d = dst;
	if (s < d && s + n > d) {
		s += n;
		d += n;
		if ((int)s%4 == 0 && (int)d%4 == 0 && n%4 == 0)
  800be8:	eb 09                	jmp    800bf3 <memmove+0x4e>
			asm volatile("std; rep movsl\n"
				:: "D" (d-4), "S" (s-4), "c" (n/4) : "cc", "memory");
		else
			asm volatile("std; rep movsb\n"
  800bea:	83 ef 01             	sub    $0x1,%edi
  800bed:	8d 72 ff             	lea    -0x1(%edx),%esi
  800bf0:	fd                   	std    
  800bf1:	f3 a4                	rep movsb %ds:(%esi),%es:(%edi)
				:: "D" (d-1), "S" (s-1), "c" (n) : "cc", "memory");
		// Some versions of GCC rely on DF being clear
		asm volatile("cld" ::: "cc");
  800bf3:	fc                   	cld    
	const char *s;
	char *d;
	
	s = src;
	d = dst;
	if (s < d && s + n > d) {
  800bf4:	eb 20                	jmp    800c16 <memmove+0x71>
			asm volatile("std; rep movsb\n"
				:: "D" (d-1), "S" (s-1), "c" (n) : "cc", "memory");
		// Some versions of GCC rely on DF being clear
		asm volatile("cld" ::: "cc");
	} else {
		if ((int)s%4 == 0 && (int)d%4 == 0 && n%4 == 0)
  800bf6:	f7 c6 03 00 00 00    	test   $0x3,%esi
  800bfc:	75 15                	jne    800c13 <memmove+0x6e>
  800bfe:	f7 c7 03 00 00 00    	test   $0x3,%edi
  800c04:	75 0d                	jne    800c13 <memmove+0x6e>
  800c06:	f6 c1 03             	test   $0x3,%cl
  800c09:	75 08                	jne    800c13 <memmove+0x6e>
			asm volatile("cld; rep movsl\n"
  800c0b:	c1 e9 02             	shr    $0x2,%ecx
  800c0e:	fc                   	cld    
  800c0f:	f3 a5                	rep movsl %ds:(%esi),%es:(%edi)
			asm volatile("std; rep movsb\n"
				:: "D" (d-1), "S" (s-1), "c" (n) : "cc", "memory");
		// Some versions of GCC rely on DF being clear
		asm volatile("cld" ::: "cc");
	} else {
		if ((int)s%4 == 0 && (int)d%4 == 0 && n%4 == 0)
  800c11:	eb 03                	jmp    800c16 <memmove+0x71>
			asm volatile("cld; rep movsl\n"
				:: "D" (d), "S" (s), "c" (n/4) : "cc", "memory");
		else
			asm volatile("cld; rep movsb\n"
  800c13:	fc                   	cld    
  800c14:	f3 a4                	rep movsb %ds:(%esi),%es:(%edi)
				:: "D" (d), "S" (s), "c" (n) : "cc", "memory");
	}
	return dst;
}
  800c16:	8b 34 24             	mov    (%esp),%esi
  800c19:	8b 7c 24 04          	mov    0x4(%esp),%edi
  800c1d:	89 ec                	mov    %ebp,%esp
  800c1f:	5d                   	pop    %ebp
  800c20:	c3                   	ret    

00800c21 <memcpy>:

/* sigh - gcc emits references to this for structure assignments! */
/* it is *not* prototyped in inc/string.h - do not use directly. */
void *
memcpy(void *dst, void *src, size_t n)
{
  800c21:	55                   	push   %ebp
  800c22:	89 e5                	mov    %esp,%ebp
  800c24:	83 ec 0c             	sub    $0xc,%esp
	return memmove(dst, src, n);
  800c27:	8b 45 10             	mov    0x10(%ebp),%eax
  800c2a:	89 44 24 08          	mov    %eax,0x8(%esp)
  800c2e:	8b 45 0c             	mov    0xc(%ebp),%eax
  800c31:	89 44 24 04          	mov    %eax,0x4(%esp)
  800c35:	8b 45 08             	mov    0x8(%ebp),%eax
  800c38:	89 04 24             	mov    %eax,(%esp)
  800c3b:	e8 65 ff ff ff       	call   800ba5 <memmove>
}
  800c40:	c9                   	leave  
  800c41:	c3                   	ret    

00800c42 <memcmp>:

int
memcmp(const void *v1, const void *v2, size_t n)
{
  800c42:	55                   	push   %ebp
  800c43:	89 e5                	mov    %esp,%ebp
  800c45:	57                   	push   %edi
  800c46:	56                   	push   %esi
  800c47:	53                   	push   %ebx
  800c48:	8b 75 08             	mov    0x8(%ebp),%esi
  800c4b:	8b 7d 0c             	mov    0xc(%ebp),%edi
  800c4e:	8b 4d 10             	mov    0x10(%ebp),%ecx
	const uint8_t *s1 = (const uint8_t *) v1;
	const uint8_t *s2 = (const uint8_t *) v2;

	while (n-- > 0) {
  800c51:	85 c9                	test   %ecx,%ecx
  800c53:	74 36                	je     800c8b <memcmp+0x49>
		if (*s1 != *s2)
  800c55:	0f b6 06             	movzbl (%esi),%eax
  800c58:	0f b6 1f             	movzbl (%edi),%ebx
  800c5b:	38 d8                	cmp    %bl,%al
  800c5d:	74 20                	je     800c7f <memcmp+0x3d>
  800c5f:	eb 14                	jmp    800c75 <memcmp+0x33>
  800c61:	0f b6 44 16 01       	movzbl 0x1(%esi,%edx,1),%eax
  800c66:	0f b6 5c 17 01       	movzbl 0x1(%edi,%edx,1),%ebx
  800c6b:	83 c2 01             	add    $0x1,%edx
  800c6e:	83 e9 01             	sub    $0x1,%ecx
  800c71:	38 d8                	cmp    %bl,%al
  800c73:	74 12                	je     800c87 <memcmp+0x45>
			return (int) *s1 - (int) *s2;
  800c75:	0f b6 c0             	movzbl %al,%eax
  800c78:	0f b6 db             	movzbl %bl,%ebx
  800c7b:	29 d8                	sub    %ebx,%eax
  800c7d:	eb 11                	jmp    800c90 <memcmp+0x4e>
memcmp(const void *v1, const void *v2, size_t n)
{
	const uint8_t *s1 = (const uint8_t *) v1;
	const uint8_t *s2 = (const uint8_t *) v2;

	while (n-- > 0) {
  800c7f:	83 e9 01             	sub    $0x1,%ecx
  800c82:	ba 00 00 00 00       	mov    $0x0,%edx
  800c87:	85 c9                	test   %ecx,%ecx
  800c89:	75 d6                	jne    800c61 <memcmp+0x1f>
  800c8b:	b8 00 00 00 00       	mov    $0x0,%eax
			return (int) *s1 - (int) *s2;
		s1++, s2++;
	}

	return 0;
}
  800c90:	5b                   	pop    %ebx
  800c91:	5e                   	pop    %esi
  800c92:	5f                   	pop    %edi
  800c93:	5d                   	pop    %ebp
  800c94:	c3                   	ret    

00800c95 <memfind>:

void *
memfind(const void *s, int c, size_t n)
{
  800c95:	55                   	push   %ebp
  800c96:	89 e5                	mov    %esp,%ebp
  800c98:	8b 45 08             	mov    0x8(%ebp),%eax
	const void *ends = (const char *) s + n;
  800c9b:	89 c2                	mov    %eax,%edx
  800c9d:	03 55 10             	add    0x10(%ebp),%edx
	for (; s < ends; s++)
  800ca0:	39 d0                	cmp    %edx,%eax
  800ca2:	73 15                	jae    800cb9 <memfind+0x24>
		if (*(const unsigned char *) s == (unsigned char) c)
  800ca4:	0f b6 4d 0c          	movzbl 0xc(%ebp),%ecx
  800ca8:	38 08                	cmp    %cl,(%eax)
  800caa:	75 06                	jne    800cb2 <memfind+0x1d>
  800cac:	eb 0b                	jmp    800cb9 <memfind+0x24>
  800cae:	38 08                	cmp    %cl,(%eax)
  800cb0:	74 07                	je     800cb9 <memfind+0x24>

void *
memfind(const void *s, int c, size_t n)
{
	const void *ends = (const char *) s + n;
	for (; s < ends; s++)
  800cb2:	83 c0 01             	add    $0x1,%eax
  800cb5:	39 c2                	cmp    %eax,%edx
  800cb7:	77 f5                	ja     800cae <memfind+0x19>
		if (*(const unsigned char *) s == (unsigned char) c)
			break;
	return (void *) s;
}
  800cb9:	5d                   	pop    %ebp
  800cba:	c3                   	ret    

00800cbb <strtol>:

long
strtol(const char *s, char **endptr, int base)
{
  800cbb:	55                   	push   %ebp
  800cbc:	89 e5                	mov    %esp,%ebp
  800cbe:	57                   	push   %edi
  800cbf:	56                   	push   %esi
  800cc0:	53                   	push   %ebx
  800cc1:	83 ec 04             	sub    $0x4,%esp
  800cc4:	8b 55 08             	mov    0x8(%ebp),%edx
  800cc7:	8b 5d 10             	mov    0x10(%ebp),%ebx
	int neg = 0;
	long val = 0;

	// gobble initial whitespace
	while (*s == ' ' || *s == '\t')
  800cca:	0f b6 02             	movzbl (%edx),%eax
  800ccd:	3c 20                	cmp    $0x20,%al
  800ccf:	74 04                	je     800cd5 <strtol+0x1a>
  800cd1:	3c 09                	cmp    $0x9,%al
  800cd3:	75 0e                	jne    800ce3 <strtol+0x28>
		s++;
  800cd5:	83 c2 01             	add    $0x1,%edx
{
	int neg = 0;
	long val = 0;

	// gobble initial whitespace
	while (*s == ' ' || *s == '\t')
  800cd8:	0f b6 02             	movzbl (%edx),%eax
  800cdb:	3c 20                	cmp    $0x20,%al
  800cdd:	74 f6                	je     800cd5 <strtol+0x1a>
  800cdf:	3c 09                	cmp    $0x9,%al
  800ce1:	74 f2                	je     800cd5 <strtol+0x1a>
		s++;

	// plus/minus sign
	if (*s == '+')
  800ce3:	3c 2b                	cmp    $0x2b,%al
  800ce5:	75 0c                	jne    800cf3 <strtol+0x38>
		s++;
  800ce7:	83 c2 01             	add    $0x1,%edx
  800cea:	c7 45 f0 00 00 00 00 	movl   $0x0,-0x10(%ebp)
  800cf1:	eb 15                	jmp    800d08 <strtol+0x4d>
	else if (*s == '-')
  800cf3:	c7 45 f0 00 00 00 00 	movl   $0x0,-0x10(%ebp)
  800cfa:	3c 2d                	cmp    $0x2d,%al
  800cfc:	75 0a                	jne    800d08 <strtol+0x4d>
		s++, neg = 1;
  800cfe:	83 c2 01             	add    $0x1,%edx
  800d01:	c7 45 f0 01 00 00 00 	movl   $0x1,-0x10(%ebp)

	// hex or octal base prefix
	if ((base == 0 || base == 16) && (s[0] == '0' && s[1] == 'x'))
  800d08:	85 db                	test   %ebx,%ebx
  800d0a:	0f 94 c0             	sete   %al
  800d0d:	74 05                	je     800d14 <strtol+0x59>
  800d0f:	83 fb 10             	cmp    $0x10,%ebx
  800d12:	75 18                	jne    800d2c <strtol+0x71>
  800d14:	80 3a 30             	cmpb   $0x30,(%edx)
  800d17:	75 13                	jne    800d2c <strtol+0x71>
  800d19:	80 7a 01 78          	cmpb   $0x78,0x1(%edx)
  800d1d:	8d 76 00             	lea    0x0(%esi),%esi
  800d20:	75 0a                	jne    800d2c <strtol+0x71>
		s += 2, base = 16;
  800d22:	83 c2 02             	add    $0x2,%edx
  800d25:	bb 10 00 00 00       	mov    $0x10,%ebx
		s++;
	else if (*s == '-')
		s++, neg = 1;

	// hex or octal base prefix
	if ((base == 0 || base == 16) && (s[0] == '0' && s[1] == 'x'))
  800d2a:	eb 15                	jmp    800d41 <strtol+0x86>
		s += 2, base = 16;
	else if (base == 0 && s[0] == '0')
  800d2c:	84 c0                	test   %al,%al
  800d2e:	66 90                	xchg   %ax,%ax
  800d30:	74 0f                	je     800d41 <strtol+0x86>
  800d32:	bb 0a 00 00 00       	mov    $0xa,%ebx
  800d37:	80 3a 30             	cmpb   $0x30,(%edx)
  800d3a:	75 05                	jne    800d41 <strtol+0x86>
		s++, base = 8;
  800d3c:	83 c2 01             	add    $0x1,%edx
  800d3f:	b3 08                	mov    $0x8,%bl
		s++, neg = 1;

	// hex or octal base prefix
	if ((base == 0 || base == 16) && (s[0] == '0' && s[1] == 'x'))
		s += 2, base = 16;
	else if (base == 0 && s[0] == '0')
  800d41:	b8 00 00 00 00       	mov    $0x0,%eax
  800d46:	89 de                	mov    %ebx,%esi

	// digits
	while (1) {
		int dig;

		if (*s >= '0' && *s <= '9')
  800d48:	0f b6 0a             	movzbl (%edx),%ecx
  800d4b:	89 cf                	mov    %ecx,%edi
  800d4d:	8d 59 d0             	lea    -0x30(%ecx),%ebx
  800d50:	80 fb 09             	cmp    $0x9,%bl
  800d53:	77 08                	ja     800d5d <strtol+0xa2>
			dig = *s - '0';
  800d55:	0f be c9             	movsbl %cl,%ecx
  800d58:	83 e9 30             	sub    $0x30,%ecx
  800d5b:	eb 1e                	jmp    800d7b <strtol+0xc0>
		else if (*s >= 'a' && *s <= 'z')
  800d5d:	8d 5f 9f             	lea    -0x61(%edi),%ebx
  800d60:	80 fb 19             	cmp    $0x19,%bl
  800d63:	77 08                	ja     800d6d <strtol+0xb2>
			dig = *s - 'a' + 10;
  800d65:	0f be c9             	movsbl %cl,%ecx
  800d68:	83 e9 57             	sub    $0x57,%ecx
  800d6b:	eb 0e                	jmp    800d7b <strtol+0xc0>
		else if (*s >= 'A' && *s <= 'Z')
  800d6d:	8d 5f bf             	lea    -0x41(%edi),%ebx
  800d70:	80 fb 19             	cmp    $0x19,%bl
  800d73:	77 15                	ja     800d8a <strtol+0xcf>
			dig = *s - 'A' + 10;
  800d75:	0f be c9             	movsbl %cl,%ecx
  800d78:	83 e9 37             	sub    $0x37,%ecx
		else
			break;
		if (dig >= base)
  800d7b:	39 f1                	cmp    %esi,%ecx
  800d7d:	7d 0b                	jge    800d8a <strtol+0xcf>
			break;
		s++, val = (val * base) + dig;
  800d7f:	83 c2 01             	add    $0x1,%edx
  800d82:	0f af c6             	imul   %esi,%eax
  800d85:	8d 04 01             	lea    (%ecx,%eax,1),%eax
		// we don't properly detect overflow!
	}
  800d88:	eb be                	jmp    800d48 <strtol+0x8d>
  800d8a:	89 c1                	mov    %eax,%ecx

	if (endptr)
  800d8c:	83 7d 0c 00          	cmpl   $0x0,0xc(%ebp)
  800d90:	74 05                	je     800d97 <strtol+0xdc>
		*endptr = (char *) s;
  800d92:	8b 5d 0c             	mov    0xc(%ebp),%ebx
  800d95:	89 13                	mov    %edx,(%ebx)
	return (neg ? -val : val);
  800d97:	89 ca                	mov    %ecx,%edx
  800d99:	f7 da                	neg    %edx
  800d9b:	83 7d f0 00          	cmpl   $0x0,-0x10(%ebp)
  800d9f:	0f 45 c2             	cmovne %edx,%eax
}
  800da2:	83 c4 04             	add    $0x4,%esp
  800da5:	5b                   	pop    %ebx
  800da6:	5e                   	pop    %esi
  800da7:	5f                   	pop    %edi
  800da8:	5d                   	pop    %ebp
  800da9:	c3                   	ret    
	...

00800dac <sys_cgetc>:
	syscall(SYS_cputs, 0, (uint32_t)s, len, 0, 0, 0);
}

int
sys_cgetc(void)
{
  800dac:	55                   	push   %ebp
  800dad:	89 e5                	mov    %esp,%ebp
  800daf:	83 ec 0c             	sub    $0xc,%esp
  800db2:	89 1c 24             	mov    %ebx,(%esp)
  800db5:	89 74 24 04          	mov    %esi,0x4(%esp)
  800db9:	89 7c 24 08          	mov    %edi,0x8(%esp)
	// 
	// The last clause tells the assembler that this can
	// potentially change the condition codes and arbitrary
	// memory locations.

	asm volatile("int %1\n"
  800dbd:	ba 00 00 00 00       	mov    $0x0,%edx
  800dc2:	b8 01 00 00 00       	mov    $0x1,%eax
  800dc7:	89 d1                	mov    %edx,%ecx
  800dc9:	89 d3                	mov    %edx,%ebx
  800dcb:	89 d7                	mov    %edx,%edi
  800dcd:	89 d6                	mov    %edx,%esi
  800dcf:	cd 30                	int    $0x30

int
sys_cgetc(void)
{
	return syscall(SYS_cgetc, 0, 0, 0, 0, 0, 0);
}
  800dd1:	8b 1c 24             	mov    (%esp),%ebx
  800dd4:	8b 74 24 04          	mov    0x4(%esp),%esi
  800dd8:	8b 7c 24 08          	mov    0x8(%esp),%edi
  800ddc:	89 ec                	mov    %ebp,%esp
  800dde:	5d                   	pop    %ebp
  800ddf:	c3                   	ret    

00800de0 <sys_cputs>:
	return ret;
}

void
sys_cputs(const char *s, size_t len)
{
  800de0:	55                   	push   %ebp
  800de1:	89 e5                	mov    %esp,%ebp
  800de3:	83 ec 0c             	sub    $0xc,%esp
  800de6:	89 1c 24             	mov    %ebx,(%esp)
  800de9:	89 74 24 04          	mov    %esi,0x4(%esp)
  800ded:	89 7c 24 08          	mov    %edi,0x8(%esp)
	// 
	// The last clause tells the assembler that this can
	// potentially change the condition codes and arbitrary
	// memory locations.

	asm volatile("int %1\n"
  800df1:	b8 00 00 00 00       	mov    $0x0,%eax
  800df6:	8b 4d 0c             	mov    0xc(%ebp),%ecx
  800df9:	8b 55 08             	mov    0x8(%ebp),%edx
  800dfc:	89 c3                	mov    %eax,%ebx
  800dfe:	89 c7                	mov    %eax,%edi
  800e00:	89 c6                	mov    %eax,%esi
  800e02:	cd 30                	int    $0x30

void
sys_cputs(const char *s, size_t len)
{
	syscall(SYS_cputs, 0, (uint32_t)s, len, 0, 0, 0);
}
  800e04:	8b 1c 24             	mov    (%esp),%ebx
  800e07:	8b 74 24 04          	mov    0x4(%esp),%esi
  800e0b:	8b 7c 24 08          	mov    0x8(%esp),%edi
  800e0f:	89 ec                	mov    %ebp,%esp
  800e11:	5d                   	pop    %ebp
  800e12:	c3                   	ret    

00800e13 <sys_ns_recv>:
  return syscall(SYS_ns_send, 0, (uint32_t)pkt, len, 0, 0, 0);
}

int
sys_ns_recv(void *pkt, uint32_t len)
{
  800e13:	55                   	push   %ebp
  800e14:	89 e5                	mov    %esp,%ebp
  800e16:	83 ec 0c             	sub    $0xc,%esp
  800e19:	89 1c 24             	mov    %ebx,(%esp)
  800e1c:	89 74 24 04          	mov    %esi,0x4(%esp)
  800e20:	89 7c 24 08          	mov    %edi,0x8(%esp)
	// 
	// The last clause tells the assembler that this can
	// potentially change the condition codes and arbitrary
	// memory locations.

	asm volatile("int %1\n"
  800e24:	bb 00 00 00 00       	mov    $0x0,%ebx
  800e29:	b8 10 00 00 00       	mov    $0x10,%eax
  800e2e:	8b 4d 0c             	mov    0xc(%ebp),%ecx
  800e31:	8b 55 08             	mov    0x8(%ebp),%edx
  800e34:	89 df                	mov    %ebx,%edi
  800e36:	89 de                	mov    %ebx,%esi
  800e38:	cd 30                	int    $0x30

int
sys_ns_recv(void *pkt, uint32_t len)
{
  return syscall(SYS_ns_recv, 0, (uint32_t)pkt, len, 0, 0, 0);
}
  800e3a:	8b 1c 24             	mov    (%esp),%ebx
  800e3d:	8b 74 24 04          	mov    0x4(%esp),%esi
  800e41:	8b 7c 24 08          	mov    0x8(%esp),%edi
  800e45:	89 ec                	mov    %ebp,%esp
  800e47:	5d                   	pop    %ebp
  800e48:	c3                   	ret    

00800e49 <sys_ns_send>:
	return (unsigned int) syscall(SYS_time_msec, 0, 0, 0, 0, 0, 0);
}

int
sys_ns_send(void *pkt, uint32_t len)
{
  800e49:	55                   	push   %ebp
  800e4a:	89 e5                	mov    %esp,%ebp
  800e4c:	83 ec 0c             	sub    $0xc,%esp
  800e4f:	89 1c 24             	mov    %ebx,(%esp)
  800e52:	89 74 24 04          	mov    %esi,0x4(%esp)
  800e56:	89 7c 24 08          	mov    %edi,0x8(%esp)
	// 
	// The last clause tells the assembler that this can
	// potentially change the condition codes and arbitrary
	// memory locations.

	asm volatile("int %1\n"
  800e5a:	bb 00 00 00 00       	mov    $0x0,%ebx
  800e5f:	b8 0f 00 00 00       	mov    $0xf,%eax
  800e64:	8b 4d 0c             	mov    0xc(%ebp),%ecx
  800e67:	8b 55 08             	mov    0x8(%ebp),%edx
  800e6a:	89 df                	mov    %ebx,%edi
  800e6c:	89 de                	mov    %ebx,%esi
  800e6e:	cd 30                	int    $0x30

int
sys_ns_send(void *pkt, uint32_t len)
{
  return syscall(SYS_ns_send, 0, (uint32_t)pkt, len, 0, 0, 0);
}
  800e70:	8b 1c 24             	mov    (%esp),%ebx
  800e73:	8b 74 24 04          	mov    0x4(%esp),%esi
  800e77:	8b 7c 24 08          	mov    0x8(%esp),%edi
  800e7b:	89 ec                	mov    %ebp,%esp
  800e7d:	5d                   	pop    %ebp
  800e7e:	c3                   	ret    

00800e7f <sys_time_msec>:
	return syscall(SYS_ipc_recv, 1, (uint32_t)dstva, 0, 0, 0, 0);
}

unsigned int
sys_time_msec(void)
{
  800e7f:	55                   	push   %ebp
  800e80:	89 e5                	mov    %esp,%ebp
  800e82:	83 ec 0c             	sub    $0xc,%esp
  800e85:	89 1c 24             	mov    %ebx,(%esp)
  800e88:	89 74 24 04          	mov    %esi,0x4(%esp)
  800e8c:	89 7c 24 08          	mov    %edi,0x8(%esp)
	// 
	// The last clause tells the assembler that this can
	// potentially change the condition codes and arbitrary
	// memory locations.

	asm volatile("int %1\n"
  800e90:	ba 00 00 00 00       	mov    $0x0,%edx
  800e95:	b8 0e 00 00 00       	mov    $0xe,%eax
  800e9a:	89 d1                	mov    %edx,%ecx
  800e9c:	89 d3                	mov    %edx,%ebx
  800e9e:	89 d7                	mov    %edx,%edi
  800ea0:	89 d6                	mov    %edx,%esi
  800ea2:	cd 30                	int    $0x30

unsigned int
sys_time_msec(void)
{
	return (unsigned int) syscall(SYS_time_msec, 0, 0, 0, 0, 0, 0);
}
  800ea4:	8b 1c 24             	mov    (%esp),%ebx
  800ea7:	8b 74 24 04          	mov    0x4(%esp),%esi
  800eab:	8b 7c 24 08          	mov    0x8(%esp),%edi
  800eaf:	89 ec                	mov    %ebp,%esp
  800eb1:	5d                   	pop    %ebp
  800eb2:	c3                   	ret    

00800eb3 <sys_ipc_recv>:
	return syscall(SYS_ipc_try_send, 1, envid, value, (uint32_t) srcva, perm, 0);
}

int
sys_ipc_recv(void *dstva)
{
  800eb3:	55                   	push   %ebp
  800eb4:	89 e5                	mov    %esp,%ebp
  800eb6:	83 ec 38             	sub    $0x38,%esp
  800eb9:	89 5d f4             	mov    %ebx,-0xc(%ebp)
  800ebc:	89 75 f8             	mov    %esi,-0x8(%ebp)
  800ebf:	89 7d fc             	mov    %edi,-0x4(%ebp)
	// 
	// The last clause tells the assembler that this can
	// potentially change the condition codes and arbitrary
	// memory locations.

	asm volatile("int %1\n"
  800ec2:	b9 00 00 00 00       	mov    $0x0,%ecx
  800ec7:	b8 0d 00 00 00       	mov    $0xd,%eax
  800ecc:	8b 55 08             	mov    0x8(%ebp),%edx
  800ecf:	89 cb                	mov    %ecx,%ebx
  800ed1:	89 cf                	mov    %ecx,%edi
  800ed3:	89 ce                	mov    %ecx,%esi
  800ed5:	cd 30                	int    $0x30
		  "b" (a3),
		  "D" (a4),
		  "S" (a5)
		: "cc", "memory");
	
	if(check && ret > 0)
  800ed7:	85 c0                	test   %eax,%eax
  800ed9:	7e 28                	jle    800f03 <sys_ipc_recv+0x50>
		panic("syscall %d returned %d (> 0)", num, ret);
  800edb:	89 44 24 10          	mov    %eax,0x10(%esp)
  800edf:	c7 44 24 0c 0d 00 00 	movl   $0xd,0xc(%esp)
  800ee6:	00 
  800ee7:	c7 44 24 08 4b 32 80 	movl   $0x80324b,0x8(%esp)
  800eee:	00 
  800eef:	c7 44 24 04 23 00 00 	movl   $0x23,0x4(%esp)
  800ef6:	00 
  800ef7:	c7 04 24 68 32 80 00 	movl   $0x803268,(%esp)
  800efe:	e8 55 f3 ff ff       	call   800258 <_panic>

int
sys_ipc_recv(void *dstva)
{
	return syscall(SYS_ipc_recv, 1, (uint32_t)dstva, 0, 0, 0, 0);
}
  800f03:	8b 5d f4             	mov    -0xc(%ebp),%ebx
  800f06:	8b 75 f8             	mov    -0x8(%ebp),%esi
  800f09:	8b 7d fc             	mov    -0x4(%ebp),%edi
  800f0c:	89 ec                	mov    %ebp,%esp
  800f0e:	5d                   	pop    %ebp
  800f0f:	c3                   	ret    

00800f10 <sys_ipc_try_send>:
	return syscall(SYS_env_set_pgfault_upcall, 1, envid, (uint32_t) upcall, 0, 0, 0);
}

int
sys_ipc_try_send(envid_t envid, uint32_t value, void *srcva, int perm)
{
  800f10:	55                   	push   %ebp
  800f11:	89 e5                	mov    %esp,%ebp
  800f13:	83 ec 38             	sub    $0x38,%esp
  800f16:	89 5d f4             	mov    %ebx,-0xc(%ebp)
  800f19:	89 75 f8             	mov    %esi,-0x8(%ebp)
  800f1c:	89 7d fc             	mov    %edi,-0x4(%ebp)
	// 
	// The last clause tells the assembler that this can
	// potentially change the condition codes and arbitrary
	// memory locations.

	asm volatile("int %1\n"
  800f1f:	be 00 00 00 00       	mov    $0x0,%esi
  800f24:	b8 0c 00 00 00       	mov    $0xc,%eax
  800f29:	8b 7d 14             	mov    0x14(%ebp),%edi
  800f2c:	8b 5d 10             	mov    0x10(%ebp),%ebx
  800f2f:	8b 4d 0c             	mov    0xc(%ebp),%ecx
  800f32:	8b 55 08             	mov    0x8(%ebp),%edx
  800f35:	cd 30                	int    $0x30
		  "b" (a3),
		  "D" (a4),
		  "S" (a5)
		: "cc", "memory");
	
	if(check && ret > 0)
  800f37:	85 c0                	test   %eax,%eax
  800f39:	7e 28                	jle    800f63 <sys_ipc_try_send+0x53>
		panic("syscall %d returned %d (> 0)", num, ret);
  800f3b:	89 44 24 10          	mov    %eax,0x10(%esp)
  800f3f:	c7 44 24 0c 0c 00 00 	movl   $0xc,0xc(%esp)
  800f46:	00 
  800f47:	c7 44 24 08 4b 32 80 	movl   $0x80324b,0x8(%esp)
  800f4e:	00 
  800f4f:	c7 44 24 04 23 00 00 	movl   $0x23,0x4(%esp)
  800f56:	00 
  800f57:	c7 04 24 68 32 80 00 	movl   $0x803268,(%esp)
  800f5e:	e8 f5 f2 ff ff       	call   800258 <_panic>

int
sys_ipc_try_send(envid_t envid, uint32_t value, void *srcva, int perm)
{
	return syscall(SYS_ipc_try_send, 1, envid, value, (uint32_t) srcva, perm, 0);
}
  800f63:	8b 5d f4             	mov    -0xc(%ebp),%ebx
  800f66:	8b 75 f8             	mov    -0x8(%ebp),%esi
  800f69:	8b 7d fc             	mov    -0x4(%ebp),%edi
  800f6c:	89 ec                	mov    %ebp,%esp
  800f6e:	5d                   	pop    %ebp
  800f6f:	c3                   	ret    

00800f70 <sys_env_set_pgfault_upcall>:
	return syscall(SYS_env_set_trapframe, 1, envid, (uint32_t) tf, 0, 0, 0);
}

int
sys_env_set_pgfault_upcall(envid_t envid, void *upcall)
{
  800f70:	55                   	push   %ebp
  800f71:	89 e5                	mov    %esp,%ebp
  800f73:	83 ec 38             	sub    $0x38,%esp
  800f76:	89 5d f4             	mov    %ebx,-0xc(%ebp)
  800f79:	89 75 f8             	mov    %esi,-0x8(%ebp)
  800f7c:	89 7d fc             	mov    %edi,-0x4(%ebp)
	// 
	// The last clause tells the assembler that this can
	// potentially change the condition codes and arbitrary
	// memory locations.

	asm volatile("int %1\n"
  800f7f:	bb 00 00 00 00       	mov    $0x0,%ebx
  800f84:	b8 0a 00 00 00       	mov    $0xa,%eax
  800f89:	8b 4d 0c             	mov    0xc(%ebp),%ecx
  800f8c:	8b 55 08             	mov    0x8(%ebp),%edx
  800f8f:	89 df                	mov    %ebx,%edi
  800f91:	89 de                	mov    %ebx,%esi
  800f93:	cd 30                	int    $0x30
		  "b" (a3),
		  "D" (a4),
		  "S" (a5)
		: "cc", "memory");
	
	if(check && ret > 0)
  800f95:	85 c0                	test   %eax,%eax
  800f97:	7e 28                	jle    800fc1 <sys_env_set_pgfault_upcall+0x51>
		panic("syscall %d returned %d (> 0)", num, ret);
  800f99:	89 44 24 10          	mov    %eax,0x10(%esp)
  800f9d:	c7 44 24 0c 0a 00 00 	movl   $0xa,0xc(%esp)
  800fa4:	00 
  800fa5:	c7 44 24 08 4b 32 80 	movl   $0x80324b,0x8(%esp)
  800fac:	00 
  800fad:	c7 44 24 04 23 00 00 	movl   $0x23,0x4(%esp)
  800fb4:	00 
  800fb5:	c7 04 24 68 32 80 00 	movl   $0x803268,(%esp)
  800fbc:	e8 97 f2 ff ff       	call   800258 <_panic>

int
sys_env_set_pgfault_upcall(envid_t envid, void *upcall)
{
	return syscall(SYS_env_set_pgfault_upcall, 1, envid, (uint32_t) upcall, 0, 0, 0);
}
  800fc1:	8b 5d f4             	mov    -0xc(%ebp),%ebx
  800fc4:	8b 75 f8             	mov    -0x8(%ebp),%esi
  800fc7:	8b 7d fc             	mov    -0x4(%ebp),%edi
  800fca:	89 ec                	mov    %ebp,%esp
  800fcc:	5d                   	pop    %ebp
  800fcd:	c3                   	ret    

00800fce <sys_env_set_trapframe>:
	return syscall(SYS_env_set_status, 1, envid, status, 0, 0, 0);
}

int
sys_env_set_trapframe(envid_t envid, struct Trapframe *tf)
{
  800fce:	55                   	push   %ebp
  800fcf:	89 e5                	mov    %esp,%ebp
  800fd1:	83 ec 38             	sub    $0x38,%esp
  800fd4:	89 5d f4             	mov    %ebx,-0xc(%ebp)
  800fd7:	89 75 f8             	mov    %esi,-0x8(%ebp)
  800fda:	89 7d fc             	mov    %edi,-0x4(%ebp)
	// 
	// The last clause tells the assembler that this can
	// potentially change the condition codes and arbitrary
	// memory locations.

	asm volatile("int %1\n"
  800fdd:	bb 00 00 00 00       	mov    $0x0,%ebx
  800fe2:	b8 09 00 00 00       	mov    $0x9,%eax
  800fe7:	8b 4d 0c             	mov    0xc(%ebp),%ecx
  800fea:	8b 55 08             	mov    0x8(%ebp),%edx
  800fed:	89 df                	mov    %ebx,%edi
  800fef:	89 de                	mov    %ebx,%esi
  800ff1:	cd 30                	int    $0x30
		  "b" (a3),
		  "D" (a4),
		  "S" (a5)
		: "cc", "memory");
	
	if(check && ret > 0)
  800ff3:	85 c0                	test   %eax,%eax
  800ff5:	7e 28                	jle    80101f <sys_env_set_trapframe+0x51>
		panic("syscall %d returned %d (> 0)", num, ret);
  800ff7:	89 44 24 10          	mov    %eax,0x10(%esp)
  800ffb:	c7 44 24 0c 09 00 00 	movl   $0x9,0xc(%esp)
  801002:	00 
  801003:	c7 44 24 08 4b 32 80 	movl   $0x80324b,0x8(%esp)
  80100a:	00 
  80100b:	c7 44 24 04 23 00 00 	movl   $0x23,0x4(%esp)
  801012:	00 
  801013:	c7 04 24 68 32 80 00 	movl   $0x803268,(%esp)
  80101a:	e8 39 f2 ff ff       	call   800258 <_panic>

int
sys_env_set_trapframe(envid_t envid, struct Trapframe *tf)
{
	return syscall(SYS_env_set_trapframe, 1, envid, (uint32_t) tf, 0, 0, 0);
}
  80101f:	8b 5d f4             	mov    -0xc(%ebp),%ebx
  801022:	8b 75 f8             	mov    -0x8(%ebp),%esi
  801025:	8b 7d fc             	mov    -0x4(%ebp),%edi
  801028:	89 ec                	mov    %ebp,%esp
  80102a:	5d                   	pop    %ebp
  80102b:	c3                   	ret    

0080102c <sys_env_set_status>:

// sys_exofork is inlined in lib.h

int
sys_env_set_status(envid_t envid, int status)
{
  80102c:	55                   	push   %ebp
  80102d:	89 e5                	mov    %esp,%ebp
  80102f:	83 ec 38             	sub    $0x38,%esp
  801032:	89 5d f4             	mov    %ebx,-0xc(%ebp)
  801035:	89 75 f8             	mov    %esi,-0x8(%ebp)
  801038:	89 7d fc             	mov    %edi,-0x4(%ebp)
	// 
	// The last clause tells the assembler that this can
	// potentially change the condition codes and arbitrary
	// memory locations.

	asm volatile("int %1\n"
  80103b:	bb 00 00 00 00       	mov    $0x0,%ebx
  801040:	b8 08 00 00 00       	mov    $0x8,%eax
  801045:	8b 4d 0c             	mov    0xc(%ebp),%ecx
  801048:	8b 55 08             	mov    0x8(%ebp),%edx
  80104b:	89 df                	mov    %ebx,%edi
  80104d:	89 de                	mov    %ebx,%esi
  80104f:	cd 30                	int    $0x30
		  "b" (a3),
		  "D" (a4),
		  "S" (a5)
		: "cc", "memory");
	
	if(check && ret > 0)
  801051:	85 c0                	test   %eax,%eax
  801053:	7e 28                	jle    80107d <sys_env_set_status+0x51>
		panic("syscall %d returned %d (> 0)", num, ret);
  801055:	89 44 24 10          	mov    %eax,0x10(%esp)
  801059:	c7 44 24 0c 08 00 00 	movl   $0x8,0xc(%esp)
  801060:	00 
  801061:	c7 44 24 08 4b 32 80 	movl   $0x80324b,0x8(%esp)
  801068:	00 
  801069:	c7 44 24 04 23 00 00 	movl   $0x23,0x4(%esp)
  801070:	00 
  801071:	c7 04 24 68 32 80 00 	movl   $0x803268,(%esp)
  801078:	e8 db f1 ff ff       	call   800258 <_panic>

int
sys_env_set_status(envid_t envid, int status)
{
	return syscall(SYS_env_set_status, 1, envid, status, 0, 0, 0);
}
  80107d:	8b 5d f4             	mov    -0xc(%ebp),%ebx
  801080:	8b 75 f8             	mov    -0x8(%ebp),%esi
  801083:	8b 7d fc             	mov    -0x4(%ebp),%edi
  801086:	89 ec                	mov    %ebp,%esp
  801088:	5d                   	pop    %ebp
  801089:	c3                   	ret    

0080108a <sys_page_unmap>:
	return syscall(SYS_page_map, 1, srcenv, (uint32_t) srcva, dstenv, (uint32_t) dstva, perm);
}

int
sys_page_unmap(envid_t envid, void *va)
{
  80108a:	55                   	push   %ebp
  80108b:	89 e5                	mov    %esp,%ebp
  80108d:	83 ec 38             	sub    $0x38,%esp
  801090:	89 5d f4             	mov    %ebx,-0xc(%ebp)
  801093:	89 75 f8             	mov    %esi,-0x8(%ebp)
  801096:	89 7d fc             	mov    %edi,-0x4(%ebp)
	// 
	// The last clause tells the assembler that this can
	// potentially change the condition codes and arbitrary
	// memory locations.

	asm volatile("int %1\n"
  801099:	bb 00 00 00 00       	mov    $0x0,%ebx
  80109e:	b8 06 00 00 00       	mov    $0x6,%eax
  8010a3:	8b 4d 0c             	mov    0xc(%ebp),%ecx
  8010a6:	8b 55 08             	mov    0x8(%ebp),%edx
  8010a9:	89 df                	mov    %ebx,%edi
  8010ab:	89 de                	mov    %ebx,%esi
  8010ad:	cd 30                	int    $0x30
		  "b" (a3),
		  "D" (a4),
		  "S" (a5)
		: "cc", "memory");
	
	if(check && ret > 0)
  8010af:	85 c0                	test   %eax,%eax
  8010b1:	7e 28                	jle    8010db <sys_page_unmap+0x51>
		panic("syscall %d returned %d (> 0)", num, ret);
  8010b3:	89 44 24 10          	mov    %eax,0x10(%esp)
  8010b7:	c7 44 24 0c 06 00 00 	movl   $0x6,0xc(%esp)
  8010be:	00 
  8010bf:	c7 44 24 08 4b 32 80 	movl   $0x80324b,0x8(%esp)
  8010c6:	00 
  8010c7:	c7 44 24 04 23 00 00 	movl   $0x23,0x4(%esp)
  8010ce:	00 
  8010cf:	c7 04 24 68 32 80 00 	movl   $0x803268,(%esp)
  8010d6:	e8 7d f1 ff ff       	call   800258 <_panic>

int
sys_page_unmap(envid_t envid, void *va)
{
	return syscall(SYS_page_unmap, 1, envid, (uint32_t) va, 0, 0, 0);
}
  8010db:	8b 5d f4             	mov    -0xc(%ebp),%ebx
  8010de:	8b 75 f8             	mov    -0x8(%ebp),%esi
  8010e1:	8b 7d fc             	mov    -0x4(%ebp),%edi
  8010e4:	89 ec                	mov    %ebp,%esp
  8010e6:	5d                   	pop    %ebp
  8010e7:	c3                   	ret    

008010e8 <sys_page_map>:
	return syscall(SYS_page_alloc, 1, envid, (uint32_t) va, perm, 0, 0);
}

int
sys_page_map(envid_t srcenv, void *srcva, envid_t dstenv, void *dstva, int perm)
{
  8010e8:	55                   	push   %ebp
  8010e9:	89 e5                	mov    %esp,%ebp
  8010eb:	83 ec 38             	sub    $0x38,%esp
  8010ee:	89 5d f4             	mov    %ebx,-0xc(%ebp)
  8010f1:	89 75 f8             	mov    %esi,-0x8(%ebp)
  8010f4:	89 7d fc             	mov    %edi,-0x4(%ebp)
	// 
	// The last clause tells the assembler that this can
	// potentially change the condition codes and arbitrary
	// memory locations.

	asm volatile("int %1\n"
  8010f7:	b8 05 00 00 00       	mov    $0x5,%eax
  8010fc:	8b 75 18             	mov    0x18(%ebp),%esi
  8010ff:	8b 7d 14             	mov    0x14(%ebp),%edi
  801102:	8b 5d 10             	mov    0x10(%ebp),%ebx
  801105:	8b 4d 0c             	mov    0xc(%ebp),%ecx
  801108:	8b 55 08             	mov    0x8(%ebp),%edx
  80110b:	cd 30                	int    $0x30
		  "b" (a3),
		  "D" (a4),
		  "S" (a5)
		: "cc", "memory");
	
	if(check && ret > 0)
  80110d:	85 c0                	test   %eax,%eax
  80110f:	7e 28                	jle    801139 <sys_page_map+0x51>
		panic("syscall %d returned %d (> 0)", num, ret);
  801111:	89 44 24 10          	mov    %eax,0x10(%esp)
  801115:	c7 44 24 0c 05 00 00 	movl   $0x5,0xc(%esp)
  80111c:	00 
  80111d:	c7 44 24 08 4b 32 80 	movl   $0x80324b,0x8(%esp)
  801124:	00 
  801125:	c7 44 24 04 23 00 00 	movl   $0x23,0x4(%esp)
  80112c:	00 
  80112d:	c7 04 24 68 32 80 00 	movl   $0x803268,(%esp)
  801134:	e8 1f f1 ff ff       	call   800258 <_panic>

int
sys_page_map(envid_t srcenv, void *srcva, envid_t dstenv, void *dstva, int perm)
{
	return syscall(SYS_page_map, 1, srcenv, (uint32_t) srcva, dstenv, (uint32_t) dstva, perm);
}
  801139:	8b 5d f4             	mov    -0xc(%ebp),%ebx
  80113c:	8b 75 f8             	mov    -0x8(%ebp),%esi
  80113f:	8b 7d fc             	mov    -0x4(%ebp),%edi
  801142:	89 ec                	mov    %ebp,%esp
  801144:	5d                   	pop    %ebp
  801145:	c3                   	ret    

00801146 <sys_page_alloc>:
	syscall(SYS_yield, 0, 0, 0, 0, 0, 0);
}

int
sys_page_alloc(envid_t envid, void *va, int perm)
{
  801146:	55                   	push   %ebp
  801147:	89 e5                	mov    %esp,%ebp
  801149:	83 ec 38             	sub    $0x38,%esp
  80114c:	89 5d f4             	mov    %ebx,-0xc(%ebp)
  80114f:	89 75 f8             	mov    %esi,-0x8(%ebp)
  801152:	89 7d fc             	mov    %edi,-0x4(%ebp)
	// 
	// The last clause tells the assembler that this can
	// potentially change the condition codes and arbitrary
	// memory locations.

	asm volatile("int %1\n"
  801155:	be 00 00 00 00       	mov    $0x0,%esi
  80115a:	b8 04 00 00 00       	mov    $0x4,%eax
  80115f:	8b 5d 10             	mov    0x10(%ebp),%ebx
  801162:	8b 4d 0c             	mov    0xc(%ebp),%ecx
  801165:	8b 55 08             	mov    0x8(%ebp),%edx
  801168:	89 f7                	mov    %esi,%edi
  80116a:	cd 30                	int    $0x30
		  "b" (a3),
		  "D" (a4),
		  "S" (a5)
		: "cc", "memory");
	
	if(check && ret > 0)
  80116c:	85 c0                	test   %eax,%eax
  80116e:	7e 28                	jle    801198 <sys_page_alloc+0x52>
		panic("syscall %d returned %d (> 0)", num, ret);
  801170:	89 44 24 10          	mov    %eax,0x10(%esp)
  801174:	c7 44 24 0c 04 00 00 	movl   $0x4,0xc(%esp)
  80117b:	00 
  80117c:	c7 44 24 08 4b 32 80 	movl   $0x80324b,0x8(%esp)
  801183:	00 
  801184:	c7 44 24 04 23 00 00 	movl   $0x23,0x4(%esp)
  80118b:	00 
  80118c:	c7 04 24 68 32 80 00 	movl   $0x803268,(%esp)
  801193:	e8 c0 f0 ff ff       	call   800258 <_panic>

int
sys_page_alloc(envid_t envid, void *va, int perm)
{
	return syscall(SYS_page_alloc, 1, envid, (uint32_t) va, perm, 0, 0);
}
  801198:	8b 5d f4             	mov    -0xc(%ebp),%ebx
  80119b:	8b 75 f8             	mov    -0x8(%ebp),%esi
  80119e:	8b 7d fc             	mov    -0x4(%ebp),%edi
  8011a1:	89 ec                	mov    %ebp,%esp
  8011a3:	5d                   	pop    %ebp
  8011a4:	c3                   	ret    

008011a5 <sys_yield>:
	 return syscall(SYS_getenvid, 0, 0, 0, 0, 0, 0);
}

void
sys_yield(void)
{
  8011a5:	55                   	push   %ebp
  8011a6:	89 e5                	mov    %esp,%ebp
  8011a8:	83 ec 0c             	sub    $0xc,%esp
  8011ab:	89 1c 24             	mov    %ebx,(%esp)
  8011ae:	89 74 24 04          	mov    %esi,0x4(%esp)
  8011b2:	89 7c 24 08          	mov    %edi,0x8(%esp)
	// 
	// The last clause tells the assembler that this can
	// potentially change the condition codes and arbitrary
	// memory locations.

	asm volatile("int %1\n"
  8011b6:	ba 00 00 00 00       	mov    $0x0,%edx
  8011bb:	b8 0b 00 00 00       	mov    $0xb,%eax
  8011c0:	89 d1                	mov    %edx,%ecx
  8011c2:	89 d3                	mov    %edx,%ebx
  8011c4:	89 d7                	mov    %edx,%edi
  8011c6:	89 d6                	mov    %edx,%esi
  8011c8:	cd 30                	int    $0x30

void
sys_yield(void)
{
	syscall(SYS_yield, 0, 0, 0, 0, 0, 0);
}
  8011ca:	8b 1c 24             	mov    (%esp),%ebx
  8011cd:	8b 74 24 04          	mov    0x4(%esp),%esi
  8011d1:	8b 7c 24 08          	mov    0x8(%esp),%edi
  8011d5:	89 ec                	mov    %ebp,%esp
  8011d7:	5d                   	pop    %ebp
  8011d8:	c3                   	ret    

008011d9 <sys_getenvid>:
	return syscall(SYS_env_destroy, 1, envid, 0, 0, 0, 0);
}

envid_t
sys_getenvid(void)
{
  8011d9:	55                   	push   %ebp
  8011da:	89 e5                	mov    %esp,%ebp
  8011dc:	83 ec 0c             	sub    $0xc,%esp
  8011df:	89 1c 24             	mov    %ebx,(%esp)
  8011e2:	89 74 24 04          	mov    %esi,0x4(%esp)
  8011e6:	89 7c 24 08          	mov    %edi,0x8(%esp)
	// 
	// The last clause tells the assembler that this can
	// potentially change the condition codes and arbitrary
	// memory locations.

	asm volatile("int %1\n"
  8011ea:	ba 00 00 00 00       	mov    $0x0,%edx
  8011ef:	b8 02 00 00 00       	mov    $0x2,%eax
  8011f4:	89 d1                	mov    %edx,%ecx
  8011f6:	89 d3                	mov    %edx,%ebx
  8011f8:	89 d7                	mov    %edx,%edi
  8011fa:	89 d6                	mov    %edx,%esi
  8011fc:	cd 30                	int    $0x30

envid_t
sys_getenvid(void)
{
	 return syscall(SYS_getenvid, 0, 0, 0, 0, 0, 0);
}
  8011fe:	8b 1c 24             	mov    (%esp),%ebx
  801201:	8b 74 24 04          	mov    0x4(%esp),%esi
  801205:	8b 7c 24 08          	mov    0x8(%esp),%edi
  801209:	89 ec                	mov    %ebp,%esp
  80120b:	5d                   	pop    %ebp
  80120c:	c3                   	ret    

0080120d <sys_env_destroy>:
	return syscall(SYS_cgetc, 0, 0, 0, 0, 0, 0);
}

int
sys_env_destroy(envid_t envid)
{
  80120d:	55                   	push   %ebp
  80120e:	89 e5                	mov    %esp,%ebp
  801210:	83 ec 38             	sub    $0x38,%esp
  801213:	89 5d f4             	mov    %ebx,-0xc(%ebp)
  801216:	89 75 f8             	mov    %esi,-0x8(%ebp)
  801219:	89 7d fc             	mov    %edi,-0x4(%ebp)
	// 
	// The last clause tells the assembler that this can
	// potentially change the condition codes and arbitrary
	// memory locations.

	asm volatile("int %1\n"
  80121c:	b9 00 00 00 00       	mov    $0x0,%ecx
  801221:	b8 03 00 00 00       	mov    $0x3,%eax
  801226:	8b 55 08             	mov    0x8(%ebp),%edx
  801229:	89 cb                	mov    %ecx,%ebx
  80122b:	89 cf                	mov    %ecx,%edi
  80122d:	89 ce                	mov    %ecx,%esi
  80122f:	cd 30                	int    $0x30
		  "b" (a3),
		  "D" (a4),
		  "S" (a5)
		: "cc", "memory");
	
	if(check && ret > 0)
  801231:	85 c0                	test   %eax,%eax
  801233:	7e 28                	jle    80125d <sys_env_destroy+0x50>
		panic("syscall %d returned %d (> 0)", num, ret);
  801235:	89 44 24 10          	mov    %eax,0x10(%esp)
  801239:	c7 44 24 0c 03 00 00 	movl   $0x3,0xc(%esp)
  801240:	00 
  801241:	c7 44 24 08 4b 32 80 	movl   $0x80324b,0x8(%esp)
  801248:	00 
  801249:	c7 44 24 04 23 00 00 	movl   $0x23,0x4(%esp)
  801250:	00 
  801251:	c7 04 24 68 32 80 00 	movl   $0x803268,(%esp)
  801258:	e8 fb ef ff ff       	call   800258 <_panic>

int
sys_env_destroy(envid_t envid)
{
	return syscall(SYS_env_destroy, 1, envid, 0, 0, 0, 0);
}
  80125d:	8b 5d f4             	mov    -0xc(%ebp),%ebx
  801260:	8b 75 f8             	mov    -0x8(%ebp),%esi
  801263:	8b 7d fc             	mov    -0x4(%ebp),%edi
  801266:	89 ec                	mov    %ebp,%esp
  801268:	5d                   	pop    %ebp
  801269:	c3                   	ret    
  80126a:	00 00                	add    %al,(%eax)
  80126c:	00 00                	add    %al,(%eax)
	...

00801270 <sfork>:
}

// Challenge!
int
sfork(void)
{
  801270:	55                   	push   %ebp
  801271:	89 e5                	mov    %esp,%ebp
  801273:	83 ec 18             	sub    $0x18,%esp
	panic("sfork not implemented");
  801276:	c7 44 24 08 76 32 80 	movl   $0x803276,0x8(%esp)
  80127d:	00 
  80127e:	c7 44 24 04 9a 00 00 	movl   $0x9a,0x4(%esp)
  801285:	00 
  801286:	c7 04 24 8c 32 80 00 	movl   $0x80328c,(%esp)
  80128d:	e8 c6 ef ff ff       	call   800258 <_panic>

00801292 <fork>:
//   Neither user exception stack should ever be marked copy-on-write,
//   so you must allocate a new page for the child's user exception stack.
//
envid_t
fork(void)
{
  801292:	55                   	push   %ebp
  801293:	89 e5                	mov    %esp,%ebp
  801295:	57                   	push   %edi
  801296:	56                   	push   %esi
  801297:	53                   	push   %ebx
  801298:	83 ec 3c             	sub    $0x3c,%esp
    int r   = 0;
    int i;
    envid_t childId = 0;
	// LAB 4: Your code here.
    // Setup parent process pgfault handler.
    set_pgfault_handler(pgfault);
  80129b:	c7 04 24 fc 14 80 00 	movl   $0x8014fc,(%esp)
  8012a2:	e8 5d 17 00 00       	call   802a04 <set_pgfault_handler>
static __inline envid_t sys_exofork(void) __attribute__((always_inline));
static __inline envid_t
sys_exofork(void)
{
	envid_t ret;
	__asm __volatile("int %2"
  8012a7:	ba 07 00 00 00       	mov    $0x7,%edx
  8012ac:	89 d0                	mov    %edx,%eax
  8012ae:	cd 30                	int    $0x30
  8012b0:	89 45 d8             	mov    %eax,-0x28(%ebp)
    childId=sys_exofork();

    if (childId<0) {
  8012b3:	85 c0                	test   %eax,%eax
  8012b5:	79 20                	jns    8012d7 <fork+0x45>
        panic("Parent: sys_exofork. Error: 0x%x\n", childId);
  8012b7:	89 44 24 0c          	mov    %eax,0xc(%esp)
  8012bb:	c7 44 24 08 fc 32 80 	movl   $0x8032fc,0x8(%esp)
  8012c2:	00 
  8012c3:	c7 44 24 04 7b 00 00 	movl   $0x7b,0x4(%esp)
  8012ca:	00 
  8012cb:	c7 04 24 8c 32 80 00 	movl   $0x80328c,(%esp)
  8012d2:	e8 81 ef ff ff       	call   800258 <_panic>
    } else if (childId>0) {
  8012d7:	83 7d d8 00          	cmpl   $0x0,-0x28(%ebp)
  8012db:	0f 8e f3 01 00 00    	jle    8014d4 <fork+0x242>
      // Setup child process' pgfault handler.
      if ((r=sys_env_set_pgfault_upcall(childId, _pgfault_upcall))) {
  8012e1:	c7 44 24 04 74 2a 80 	movl   $0x802a74,0x4(%esp)
  8012e8:	00 
  8012e9:	8b 45 d8             	mov    -0x28(%ebp),%eax
  8012ec:	89 04 24             	mov    %eax,(%esp)
  8012ef:	e8 7c fc ff ff       	call   800f70 <sys_env_set_pgfault_upcall>
  8012f4:	85 c0                	test   %eax,%eax
  8012f6:	74 20                	je     801318 <fork+0x86>
          panic("Child: sys_env_set_pgfault_upcall. Error: %d\n", r);
  8012f8:	89 44 24 0c          	mov    %eax,0xc(%esp)
  8012fc:	c7 44 24 08 20 33 80 	movl   $0x803320,0x8(%esp)
  801303:	00 
  801304:	c7 44 24 04 7f 00 00 	movl   $0x7f,0x4(%esp)
  80130b:	00 
  80130c:	c7 04 24 8c 32 80 00 	movl   $0x80328c,(%esp)
  801313:	e8 40 ef ff ff       	call   800258 <_panic>
      }
      
      // Setup child's Image.
      // Allocate page for child's user exception stack.
      if ((r=sys_page_alloc(childId, (void *)(UXSTACKTOP-PGSIZE), PTE_U|PTE_P|PTE_W))<0) {
  801318:	c7 44 24 08 07 00 00 	movl   $0x7,0x8(%esp)
  80131f:	00 
  801320:	c7 44 24 04 00 f0 bf 	movl   $0xeebff000,0x4(%esp)
  801327:	ee 
  801328:	8b 45 d8             	mov    -0x28(%ebp),%eax
  80132b:	89 04 24             	mov    %eax,(%esp)
  80132e:	e8 13 fe ff ff       	call   801146 <sys_page_alloc>
  801333:	85 c0                	test   %eax,%eax
  801335:	79 20                	jns    801357 <fork+0xc5>
          panic("Parent: sys_page_alloc. Error: 0x%x\n", r);           
  801337:	89 44 24 0c          	mov    %eax,0xc(%esp)
  80133b:	c7 44 24 08 50 33 80 	movl   $0x803350,0x8(%esp)
  801342:	00 
  801343:	c7 44 24 04 85 00 00 	movl   $0x85,0x4(%esp)
  80134a:	00 
  80134b:	c7 04 24 8c 32 80 00 	movl   $0x80328c,(%esp)
  801352:	e8 01 ef ff ff       	call   800258 <_panic>
  801357:	be 00 00 80 00       	mov    $0x800000,%esi
  80135c:	bb 00 00 80 00       	mov    $0x800000,%ebx
      }

      // Copy Parent's address space to child.
      for (i=UTEXT;i<USTACKTOP;i+=PGSIZE)
        if (vpd[VPD(i)]&PTE_P)
  801361:	bf 00 d0 7b ef       	mov    $0xef7bd000,%edi
  801366:	89 f0                	mov    %esi,%eax
  801368:	c1 e8 16             	shr    $0x16,%eax
  80136b:	8b 04 87             	mov    (%edi,%eax,4),%eax
  80136e:	a8 01                	test   $0x1,%al
  801370:	0f 84 13 01 00 00    	je     801489 <fork+0x1f7>
// 
static int
duppage(envid_t envid, unsigned pn)
{
	int r           = 0;
  int perm        = vpt[VPN(pn)]&PTE_USER;
  801376:	89 f0                	mov    %esi,%eax
  801378:	c1 e8 0c             	shr    $0xc,%eax
  80137b:	8b 04 85 00 00 40 ef 	mov    -0x10c00000(,%eax,4),%eax
  801382:	89 45 e4             	mov    %eax,-0x1c(%ebp)
  801385:	25 07 0e 00 00       	and    $0xe07,%eax
  80138a:	89 45 e0             	mov    %eax,-0x20(%ebp)
  envid_t env_id  = sys_getenvid();
  80138d:	e8 47 fe ff ff       	call   8011d9 <sys_getenvid>
  801392:	89 45 dc             	mov    %eax,-0x24(%ebp)

	// LAB 4: Your code here.
  if ((perm&PTE_P) && (perm&PTE_W || perm&PTE_COW) && (!(perm&PTE_SHARE))) {
  801395:	f6 45 e4 01          	testb  $0x1,-0x1c(%ebp)
  801399:	0f 84 ea 00 00 00    	je     801489 <fork+0x1f7>
  80139f:	f7 45 e0 02 08 00 00 	testl  $0x802,-0x20(%ebp)
  8013a6:	0f 84 9d 00 00 00    	je     801449 <fork+0x1b7>
  8013ac:	f7 45 e0 00 04 00 00 	testl  $0x400,-0x20(%ebp)
  8013b3:	0f 85 90 00 00 00    	jne    801449 <fork+0x1b7>
    perm    &= (~PTE_W);
  8013b9:	8b 45 e0             	mov    -0x20(%ebp),%eax
  8013bc:	83 e0 fd             	and    $0xfffffffd,%eax
    perm    |= PTE_COW;
  8013bf:	80 cc 08             	or     $0x8,%ah
  8013c2:	89 45 e4             	mov    %eax,-0x1c(%ebp)
    
    if ((r=sys_page_map(env_id, (void *)pn, envid, (void *)pn, perm))<0)
  8013c5:	89 75 e0             	mov    %esi,-0x20(%ebp)
  8013c8:	89 44 24 10          	mov    %eax,0x10(%esp)
  8013cc:	89 74 24 0c          	mov    %esi,0xc(%esp)
  8013d0:	8b 45 d8             	mov    -0x28(%ebp),%eax
  8013d3:	89 44 24 08          	mov    %eax,0x8(%esp)
  8013d7:	89 74 24 04          	mov    %esi,0x4(%esp)
  8013db:	8b 45 dc             	mov    -0x24(%ebp),%eax
  8013de:	89 04 24             	mov    %eax,(%esp)
  8013e1:	e8 02 fd ff ff       	call   8010e8 <sys_page_map>
  8013e6:	85 c0                	test   %eax,%eax
  8013e8:	79 1b                	jns    801405 <fork+0x173>
      cprintf("[0x%x] Mapping to CHILD: sys_page_map. Address 0x%x. Error: %d\n", env_id, pn, r);
  8013ea:	89 44 24 0c          	mov    %eax,0xc(%esp)
  8013ee:	89 74 24 08          	mov    %esi,0x8(%esp)
  8013f2:	8b 45 dc             	mov    -0x24(%ebp),%eax
  8013f5:	89 44 24 04          	mov    %eax,0x4(%esp)
  8013f9:	c7 04 24 78 33 80 00 	movl   $0x803378,(%esp)
  801400:	e8 18 ef ff ff       	call   80031d <cprintf>
    // Map permissions back to parent on COW.
    if ((r=sys_page_map(envid, (void *)pn, env_id, (void *)pn, perm))<0)
  801405:	8b 45 e4             	mov    -0x1c(%ebp),%eax
  801408:	89 44 24 10          	mov    %eax,0x10(%esp)
  80140c:	8b 45 e0             	mov    -0x20(%ebp),%eax
  80140f:	89 44 24 0c          	mov    %eax,0xc(%esp)
  801413:	8b 45 dc             	mov    -0x24(%ebp),%eax
  801416:	89 44 24 08          	mov    %eax,0x8(%esp)
  80141a:	8b 45 e0             	mov    -0x20(%ebp),%eax
  80141d:	89 44 24 04          	mov    %eax,0x4(%esp)
  801421:	8b 45 d8             	mov    -0x28(%ebp),%eax
  801424:	89 04 24             	mov    %eax,(%esp)
  801427:	e8 bc fc ff ff       	call   8010e8 <sys_page_map>
  80142c:	85 c0                	test   %eax,%eax
  80142e:	79 59                	jns    801489 <fork+0x1f7>
      cprintf("[0x%x] Mapping to PARENT: sys_page_map. Error: %d\n", env_id, r);
  801430:	89 44 24 08          	mov    %eax,0x8(%esp)
  801434:	8b 45 dc             	mov    -0x24(%ebp),%eax
  801437:	89 44 24 04          	mov    %eax,0x4(%esp)
  80143b:	c7 04 24 b8 33 80 00 	movl   $0x8033b8,(%esp)
  801442:	e8 d6 ee ff ff       	call   80031d <cprintf>
  801447:	eb 40                	jmp    801489 <fork+0x1f7>
  } else if (perm&PTE_P){
    if ((r=sys_page_map(env_id, (void *)pn, envid, (void *)pn, perm))<0)
  801449:	8b 45 e0             	mov    -0x20(%ebp),%eax
  80144c:	89 44 24 10          	mov    %eax,0x10(%esp)
  801450:	89 74 24 0c          	mov    %esi,0xc(%esp)
  801454:	8b 45 d8             	mov    -0x28(%ebp),%eax
  801457:	89 44 24 08          	mov    %eax,0x8(%esp)
  80145b:	89 74 24 04          	mov    %esi,0x4(%esp)
  80145f:	8b 45 dc             	mov    -0x24(%ebp),%eax
  801462:	89 04 24             	mov    %eax,(%esp)
  801465:	e8 7e fc ff ff       	call   8010e8 <sys_page_map>
  80146a:	85 c0                	test   %eax,%eax
  80146c:	79 1b                	jns    801489 <fork+0x1f7>
      cprintf("[0x%x] Mapping to CHILD: sys_page_map. Address 0x%x. Error: %d\n", env_id, pn, r);
  80146e:	89 44 24 0c          	mov    %eax,0xc(%esp)
  801472:	89 74 24 08          	mov    %esi,0x8(%esp)
  801476:	8b 45 dc             	mov    -0x24(%ebp),%eax
  801479:	89 44 24 04          	mov    %eax,0x4(%esp)
  80147d:	c7 04 24 78 33 80 00 	movl   $0x803378,(%esp)
  801484:	e8 94 ee ff ff       	call   80031d <cprintf>
      if ((r=sys_page_alloc(childId, (void *)(UXSTACKTOP-PGSIZE), PTE_U|PTE_P|PTE_W))<0) {
          panic("Parent: sys_page_alloc. Error: 0x%x\n", r);           
      }

      // Copy Parent's address space to child.
      for (i=UTEXT;i<USTACKTOP;i+=PGSIZE)
  801489:	81 c3 00 10 00 00    	add    $0x1000,%ebx
  80148f:	89 de                	mov    %ebx,%esi
  801491:	81 fb 00 e0 bf ee    	cmp    $0xeebfe000,%ebx
  801497:	0f 85 c9 fe ff ff    	jne    801366 <fork+0xd4>
        if (vpd[VPD(i)]&PTE_P)
          duppage(childId, i);

      // Set child as runnable.
      if ((r = sys_env_set_status(childId, ENV_RUNNABLE)) < 0)
  80149d:	c7 44 24 04 01 00 00 	movl   $0x1,0x4(%esp)
  8014a4:	00 
  8014a5:	8b 45 d8             	mov    -0x28(%ebp),%eax
  8014a8:	89 04 24             	mov    %eax,(%esp)
  8014ab:	e8 7c fb ff ff       	call   80102c <sys_env_set_status>
  8014b0:	85 c0                	test   %eax,%eax
  8014b2:	79 3d                	jns    8014f1 <fork+0x25f>
        panic("Parent: sys_env_set_status: %e\n", r);
  8014b4:	89 44 24 0c          	mov    %eax,0xc(%esp)
  8014b8:	c7 44 24 08 ec 33 80 	movl   $0x8033ec,0x8(%esp)
  8014bf:	00 
  8014c0:	c7 44 24 04 8f 00 00 	movl   $0x8f,0x4(%esp)
  8014c7:	00 
  8014c8:	c7 04 24 8c 32 80 00 	movl   $0x80328c,(%esp)
  8014cf:	e8 84 ed ff ff       	call   800258 <_panic>
    } else if (childId==0) {
  8014d4:	83 7d d8 00          	cmpl   $0x0,-0x28(%ebp)
  8014d8:	75 17                	jne    8014f1 <fork+0x25f>
      env = &envs [ENVX(sys_getenvid())];
  8014da:	e8 fa fc ff ff       	call   8011d9 <sys_getenvid>
  8014df:	25 ff 03 00 00       	and    $0x3ff,%eax
  8014e4:	6b c0 7c             	imul   $0x7c,%eax,%eax
  8014e7:	05 00 00 c0 ee       	add    $0xeec00000,%eax
  8014ec:	a3 74 70 80 00       	mov    %eax,0x807074
    }
    return childId;
}
  8014f1:	8b 45 d8             	mov    -0x28(%ebp),%eax
  8014f4:	83 c4 3c             	add    $0x3c,%esp
  8014f7:	5b                   	pop    %ebx
  8014f8:	5e                   	pop    %esi
  8014f9:	5f                   	pop    %edi
  8014fa:	5d                   	pop    %ebp
  8014fb:	c3                   	ret    

008014fc <pgfault>:
// Custom page fault handler - if faulting page is copy-on-write,
// map in our own private writable copy.
//
static void
pgfault(struct UTrapframe *utf)
{
  8014fc:	55                   	push   %ebp
  8014fd:	89 e5                	mov    %esp,%ebp
  8014ff:	57                   	push   %edi
  801500:	56                   	push   %esi
  801501:	53                   	push   %ebx
  801502:	83 ec 3c             	sub    $0x3c,%esp
  void *addr    = (void *) utf->utf_fault_va;
  801505:	8b 45 08             	mov    0x8(%ebp),%eax
  801508:	8b 38                	mov    (%eax),%edi
  uint32_t err  = utf->utf_err;
  80150a:	8b 50 04             	mov    0x4(%eax),%edx
  80150d:	89 55 e4             	mov    %edx,-0x1c(%ebp)
  int r         = 0;
  int perm      = 0;
  void *align   = (void *)((int)addr&(~0xFFF));
  801510:	89 fe                	mov    %edi,%esi
  801512:	81 e6 00 f0 ff ff    	and    $0xfffff000,%esi
  envid_t envid = sys_getenvid();
  801518:	e8 bc fc ff ff       	call   8011d9 <sys_getenvid>
  80151d:	89 c3                	mov    %eax,%ebx
	// copy-on-write page.  If not, panic.
	// Hint:
	//   Use the read-only page table mappings at vpt
	//   (see <inc/memlayout.h>).

  if ((vpd[VPD(align)]&PTE_P) && (vpt[VPN(align)]&PTE_P))
  80151f:	89 f2                	mov    %esi,%edx
  801521:	89 f0                	mov    %esi,%eax
  801523:	c1 e8 16             	shr    $0x16,%eax
  801526:	8b 04 85 00 d0 7b ef 	mov    -0x10843000(,%eax,4),%eax
  80152d:	a8 01                	test   $0x1,%al
  80152f:	74 3e                	je     80156f <pgfault+0x73>
  801531:	c1 ea 0c             	shr    $0xc,%edx
  801534:	8b 04 95 00 00 40 ef 	mov    -0x10c00000(,%edx,4),%eax
  80153b:	a8 01                	test   $0x1,%al
  80153d:	74 30                	je     80156f <pgfault+0x73>
    perm  = vpt[VPN(addr)]&PTE_USER;
  80153f:	c1 ef 0c             	shr    $0xc,%edi
  801542:	8b 3c bd 00 00 40 ef 	mov    -0x10c00000(,%edi,4),%edi
	// page to the old page's address.
	// Hint:
	//   You should make three system calls.
	//   No need to explicitly delete the old page's mapping.
	// LAB 4: Your code here.
  perm    &= (~PTE_COW);
  801549:	81 e7 07 06 00 00    	and    $0x607,%edi
  perm    |= PTE_W;
  80154f:	83 cf 02             	or     $0x2,%edi
  if (!(r=sys_page_alloc(envid, (void *)PFTEMP, perm))) {
  801552:	89 7c 24 08          	mov    %edi,0x8(%esp)
  801556:	c7 44 24 04 00 f0 7f 	movl   $0x7ff000,0x4(%esp)
  80155d:	00 
  80155e:	89 1c 24             	mov    %ebx,(%esp)
  801561:	e8 e0 fb ff ff       	call   801146 <sys_page_alloc>
  801566:	85 c0                	test   %eax,%eax
  801568:	74 46                	je     8015b0 <pgfault+0xb4>
  80156a:	e9 cd 00 00 00       	jmp    80163c <pgfault+0x140>
	//   (see <inc/memlayout.h>).

  if ((vpd[VPD(align)]&PTE_P) && (vpt[VPN(align)]&PTE_P))
    perm  = vpt[VPN(addr)]&PTE_USER;
  else {
    cprintf("Tryig to acess address: %x eip: %x Err: %x\n", align, utf->utf_eip, err);
  80156f:	8b 45 e4             	mov    -0x1c(%ebp),%eax
  801572:	89 44 24 0c          	mov    %eax,0xc(%esp)
  801576:	8b 55 08             	mov    0x8(%ebp),%edx
  801579:	8b 42 28             	mov    0x28(%edx),%eax
  80157c:	89 44 24 08          	mov    %eax,0x8(%esp)
  801580:	89 74 24 04          	mov    %esi,0x4(%esp)
  801584:	c7 04 24 0c 34 80 00 	movl   $0x80340c,(%esp)
  80158b:	e8 8d ed ff ff       	call   80031d <cprintf>
    panic("Go to hell :[%x]\n", envid);
  801590:	89 5c 24 0c          	mov    %ebx,0xc(%esp)
  801594:	c7 44 24 08 97 32 80 	movl   $0x803297,0x8(%esp)
  80159b:	00 
  80159c:	c7 44 24 04 24 00 00 	movl   $0x24,0x4(%esp)
  8015a3:	00 
  8015a4:	c7 04 24 8c 32 80 00 	movl   $0x80328c,(%esp)
  8015ab:	e8 a8 ec ff ff       	call   800258 <_panic>
	//   No need to explicitly delete the old page's mapping.
	// LAB 4: Your code here.
  perm    &= (~PTE_COW);
  perm    |= PTE_W;
  if (!(r=sys_page_alloc(envid, (void *)PFTEMP, perm))) {
    memmove((void *)PFTEMP, align, PGSIZE);
  8015b0:	c7 44 24 08 00 10 00 	movl   $0x1000,0x8(%esp)
  8015b7:	00 
  8015b8:	89 74 24 04          	mov    %esi,0x4(%esp)
  8015bc:	c7 04 24 00 f0 7f 00 	movl   $0x7ff000,(%esp)
  8015c3:	e8 dd f5 ff ff       	call   800ba5 <memmove>
    if((r=sys_page_map(envid, (void *)PFTEMP, envid, align, perm)))
  8015c8:	89 7c 24 10          	mov    %edi,0x10(%esp)
  8015cc:	89 74 24 0c          	mov    %esi,0xc(%esp)
  8015d0:	89 5c 24 08          	mov    %ebx,0x8(%esp)
  8015d4:	c7 44 24 04 00 f0 7f 	movl   $0x7ff000,0x4(%esp)
  8015db:	00 
  8015dc:	89 1c 24             	mov    %ebx,(%esp)
  8015df:	e8 04 fb ff ff       	call   8010e8 <sys_page_map>
  8015e4:	85 c0                	test   %eax,%eax
  8015e6:	74 20                	je     801608 <pgfault+0x10c>
      panic("sys_page_map. Error: 0x%x\n", r);
  8015e8:	89 44 24 0c          	mov    %eax,0xc(%esp)
  8015ec:	c7 44 24 08 a9 32 80 	movl   $0x8032a9,0x8(%esp)
  8015f3:	00 
  8015f4:	c7 44 24 04 34 00 00 	movl   $0x34,0x4(%esp)
  8015fb:	00 
  8015fc:	c7 04 24 8c 32 80 00 	movl   $0x80328c,(%esp)
  801603:	e8 50 ec ff ff       	call   800258 <_panic>

    if ((r=sys_page_unmap(envid, (void *)PFTEMP)))
  801608:	c7 44 24 04 00 f0 7f 	movl   $0x7ff000,0x4(%esp)
  80160f:	00 
  801610:	89 1c 24             	mov    %ebx,(%esp)
  801613:	e8 72 fa ff ff       	call   80108a <sys_page_unmap>
  801618:	85 c0                	test   %eax,%eax
  80161a:	74 40                	je     80165c <pgfault+0x160>
      panic("sys_page_unmap. Error: 0x%x\n", r);
  80161c:	89 44 24 0c          	mov    %eax,0xc(%esp)
  801620:	c7 44 24 08 c4 32 80 	movl   $0x8032c4,0x8(%esp)
  801627:	00 
  801628:	c7 44 24 04 37 00 00 	movl   $0x37,0x4(%esp)
  80162f:	00 
  801630:	c7 04 24 8c 32 80 00 	movl   $0x80328c,(%esp)
  801637:	e8 1c ec ff ff       	call   800258 <_panic>
  } else
    panic("sys_page_alloc. Error: %d\n", r);
  80163c:	89 44 24 0c          	mov    %eax,0xc(%esp)
  801640:	c7 44 24 08 e1 32 80 	movl   $0x8032e1,0x8(%esp)
  801647:	00 
  801648:	c7 44 24 04 39 00 00 	movl   $0x39,0x4(%esp)
  80164f:	00 
  801650:	c7 04 24 8c 32 80 00 	movl   $0x80328c,(%esp)
  801657:	e8 fc eb ff ff       	call   800258 <_panic>
}
  80165c:	83 c4 3c             	add    $0x3c,%esp
  80165f:	5b                   	pop    %ebx
  801660:	5e                   	pop    %esi
  801661:	5f                   	pop    %edi
  801662:	5d                   	pop    %ebp
  801663:	c3                   	ret    
	...

00801670 <fd2num>:
// File descriptor manipulators
// --------------------------------------------------------------

int
fd2num(struct Fd *fd)
{
  801670:	55                   	push   %ebp
  801671:	89 e5                	mov    %esp,%ebp
  801673:	8b 45 08             	mov    0x8(%ebp),%eax
  801676:	05 00 00 00 30       	add    $0x30000000,%eax
  80167b:	c1 e8 0c             	shr    $0xc,%eax
	return ((uintptr_t) fd - FDTABLE) / PGSIZE;
}
  80167e:	5d                   	pop    %ebp
  80167f:	c3                   	ret    

00801680 <fd2data>:

char*
fd2data(struct Fd *fd)
{
  801680:	55                   	push   %ebp
  801681:	89 e5                	mov    %esp,%ebp
  801683:	83 ec 04             	sub    $0x4,%esp
	return INDEX2DATA(fd2num(fd));
  801686:	8b 45 08             	mov    0x8(%ebp),%eax
  801689:	89 04 24             	mov    %eax,(%esp)
  80168c:	e8 df ff ff ff       	call   801670 <fd2num>
  801691:	05 20 00 0d 00       	add    $0xd0020,%eax
  801696:	c1 e0 0c             	shl    $0xc,%eax
}
  801699:	c9                   	leave  
  80169a:	c3                   	ret    

0080169b <fd_alloc>:
// Returns 0 on success, < 0 on error.  Errors are:
//	-E_MAX_FD: no more file descriptors
// On error, *fd_store is set to 0.
int
fd_alloc(struct Fd **fd_store)
{
  80169b:	55                   	push   %ebp
  80169c:	89 e5                	mov    %esp,%ebp
  80169e:	57                   	push   %edi
  80169f:	56                   	push   %esi
  8016a0:	53                   	push   %ebx
  8016a1:	8b 7d 08             	mov    0x8(%ebp),%edi
	int i;
	struct Fd *fd;

	for (i = 0; i < MAXFD; i++) {
		fd = INDEX2FD(i);
		if ((vpd[PDX(fd)] & PTE_P) == 0 || (vpt[VPN(fd)] & PTE_P) == 0) {
  8016a4:	a1 00 dd 7b ef       	mov    0xef7bdd00,%eax
  8016a9:	a8 01                	test   $0x1,%al
  8016ab:	74 36                	je     8016e3 <fd_alloc+0x48>
  8016ad:	a1 00 00 74 ef       	mov    0xef740000,%eax
  8016b2:	a8 01                	test   $0x1,%al
  8016b4:	74 2d                	je     8016e3 <fd_alloc+0x48>
  8016b6:	b8 00 10 00 d0       	mov    $0xd0001000,%eax
  8016bb:	b9 00 d0 7b ef       	mov    $0xef7bd000,%ecx
  8016c0:	be 00 00 40 ef       	mov    $0xef400000,%esi
  8016c5:	89 c3                	mov    %eax,%ebx
  8016c7:	89 c2                	mov    %eax,%edx
  8016c9:	c1 ea 16             	shr    $0x16,%edx
  8016cc:	8b 14 91             	mov    (%ecx,%edx,4),%edx
  8016cf:	f6 c2 01             	test   $0x1,%dl
  8016d2:	74 14                	je     8016e8 <fd_alloc+0x4d>
  8016d4:	89 c2                	mov    %eax,%edx
  8016d6:	c1 ea 0c             	shr    $0xc,%edx
  8016d9:	8b 14 96             	mov    (%esi,%edx,4),%edx
  8016dc:	f6 c2 01             	test   $0x1,%dl
  8016df:	75 10                	jne    8016f1 <fd_alloc+0x56>
  8016e1:	eb 05                	jmp    8016e8 <fd_alloc+0x4d>
  8016e3:	bb 00 00 00 d0       	mov    $0xd0000000,%ebx
			*fd_store = fd;
  8016e8:	89 1f                	mov    %ebx,(%edi)
  8016ea:	b8 00 00 00 00       	mov    $0x0,%eax
			return 0;
  8016ef:	eb 17                	jmp    801708 <fd_alloc+0x6d>
  8016f1:	05 00 10 00 00       	add    $0x1000,%eax
fd_alloc(struct Fd **fd_store)
{
	int i;
	struct Fd *fd;

	for (i = 0; i < MAXFD; i++) {
  8016f6:	3d 00 00 02 d0       	cmp    $0xd0020000,%eax
  8016fb:	75 c8                	jne    8016c5 <fd_alloc+0x2a>
		if ((vpd[PDX(fd)] & PTE_P) == 0 || (vpt[VPN(fd)] & PTE_P) == 0) {
			*fd_store = fd;
			return 0;
		}
	}
	*fd_store = 0;
  8016fd:	c7 07 00 00 00 00    	movl   $0x0,(%edi)
  801703:	b8 f6 ff ff ff       	mov    $0xfffffff6,%eax
	return -E_MAX_OPEN;
}
  801708:	5b                   	pop    %ebx
  801709:	5e                   	pop    %esi
  80170a:	5f                   	pop    %edi
  80170b:	5d                   	pop    %ebp
  80170c:	c3                   	ret    

0080170d <fd_lookup>:
// Returns 0 on success (the page is in range and mapped), < 0 on error.
// Errors are:
//	-E_INVAL: fdnum was either not in range or not mapped.
int
fd_lookup(int fdnum, struct Fd **fd_store)
{
  80170d:	55                   	push   %ebp
  80170e:	89 e5                	mov    %esp,%ebp
	struct Fd *fd=NULL;

	if (fdnum < 0 || fdnum >= MAXFD) {
  801710:	8b 45 08             	mov    0x8(%ebp),%eax
  801713:	83 f8 1f             	cmp    $0x1f,%eax
  801716:	77 36                	ja     80174e <fd_lookup+0x41>
		if (debug)
			cprintf("[%08x] bad fd %d\n", env->env_id, fd);
		return -E_INVAL;
	}
	fd = INDEX2FD(fdnum);
  801718:	05 00 00 0d 00       	add    $0xd0000,%eax
  80171d:	c1 e0 0c             	shl    $0xc,%eax
	if (!(vpd[PDX(fd)] & PTE_P) || !(vpt[VPN(fd)] & PTE_P)) {
  801720:	89 c2                	mov    %eax,%edx
  801722:	c1 ea 16             	shr    $0x16,%edx
  801725:	8b 14 95 00 d0 7b ef 	mov    -0x10843000(,%edx,4),%edx
  80172c:	f6 c2 01             	test   $0x1,%dl
  80172f:	74 1d                	je     80174e <fd_lookup+0x41>
  801731:	89 c2                	mov    %eax,%edx
  801733:	c1 ea 0c             	shr    $0xc,%edx
  801736:	8b 14 95 00 00 40 ef 	mov    -0x10c00000(,%edx,4),%edx
  80173d:	f6 c2 01             	test   $0x1,%dl
  801740:	74 0c                	je     80174e <fd_lookup+0x41>
		if (debug)
			cprintf("[%08x] closed fd %d\n", env->env_id, fd);
		return -E_INVAL;
	}
	*fd_store = fd;
  801742:	8b 55 0c             	mov    0xc(%ebp),%edx
  801745:	89 02                	mov    %eax,(%edx)
  801747:	b8 00 00 00 00       	mov    $0x0,%eax
	return 0;
  80174c:	eb 05                	jmp    801753 <fd_lookup+0x46>
  80174e:	b8 fd ff ff ff       	mov    $0xfffffffd,%eax
}
  801753:	5d                   	pop    %ebp
  801754:	c3                   	ret    

00801755 <seek>:
	return (*dev->dev_write)(fd, buf, n);
}

int
seek(int fdnum, off_t offset)
{
  801755:	55                   	push   %ebp
  801756:	89 e5                	mov    %esp,%ebp
  801758:	83 ec 18             	sub    $0x18,%esp
	int r;
	struct Fd *fd;
	if ((r = fd_lookup(fdnum, &fd)) < 0)
  80175b:	8d 45 fc             	lea    -0x4(%ebp),%eax
  80175e:	89 44 24 04          	mov    %eax,0x4(%esp)
  801762:	8b 45 08             	mov    0x8(%ebp),%eax
  801765:	89 04 24             	mov    %eax,(%esp)
  801768:	e8 a0 ff ff ff       	call   80170d <fd_lookup>
  80176d:	85 c0                	test   %eax,%eax
  80176f:	78 0e                	js     80177f <seek+0x2a>
		return r;
	fd->fd_offset = offset;
  801771:	8b 45 fc             	mov    -0x4(%ebp),%eax
  801774:	8b 55 0c             	mov    0xc(%ebp),%edx
  801777:	89 50 04             	mov    %edx,0x4(%eax)
  80177a:	b8 00 00 00 00       	mov    $0x0,%eax
	return 0;
}
  80177f:	c9                   	leave  
  801780:	c3                   	ret    

00801781 <dev_lookup>:
	0
};

int
dev_lookup(int dev_id, struct Dev **dev)
{
  801781:	55                   	push   %ebp
  801782:	89 e5                	mov    %esp,%ebp
  801784:	56                   	push   %esi
  801785:	53                   	push   %ebx
  801786:	83 ec 10             	sub    $0x10,%esp
  801789:	8b 4d 08             	mov    0x8(%ebp),%ecx
  80178c:	8b 5d 0c             	mov    0xc(%ebp),%ebx
	int i;
	for (i = 0; devtab[i]; i++)
		if (devtab[i]->dev_id == dev_id) {
			*dev = devtab[i];
			return 0;
  80178f:	ba 00 00 00 00       	mov    $0x0,%edx
int
dev_lookup(int dev_id, struct Dev **dev)
{
	int i;
	for (i = 0; devtab[i]; i++)
		if (devtab[i]->dev_id == dev_id) {
  801794:	b8 04 70 80 00       	mov    $0x807004,%eax
  801799:	39 0d 04 70 80 00    	cmp    %ecx,0x807004
  80179f:	75 11                	jne    8017b2 <dev_lookup+0x31>
  8017a1:	eb 04                	jmp    8017a7 <dev_lookup+0x26>
  8017a3:	39 08                	cmp    %ecx,(%eax)
  8017a5:	75 10                	jne    8017b7 <dev_lookup+0x36>
			*dev = devtab[i];
  8017a7:	89 03                	mov    %eax,(%ebx)
  8017a9:	b8 00 00 00 00       	mov    $0x0,%eax
			return 0;
  8017ae:	66 90                	xchg   %ax,%ax
  8017b0:	eb 36                	jmp    8017e8 <dev_lookup+0x67>

int
dev_lookup(int dev_id, struct Dev **dev)
{
	int i;
	for (i = 0; devtab[i]; i++)
  8017b2:	be b4 34 80 00       	mov    $0x8034b4,%esi
  8017b7:	83 c2 01             	add    $0x1,%edx
  8017ba:	8b 04 96             	mov    (%esi,%edx,4),%eax
  8017bd:	85 c0                	test   %eax,%eax
  8017bf:	75 e2                	jne    8017a3 <dev_lookup+0x22>
		if (devtab[i]->dev_id == dev_id) {
			*dev = devtab[i];
			return 0;
		}
	cprintf("[%08x] unknown device type %d\n", env->env_id, dev_id);
  8017c1:	a1 74 70 80 00       	mov    0x807074,%eax
  8017c6:	8b 40 4c             	mov    0x4c(%eax),%eax
  8017c9:	89 4c 24 08          	mov    %ecx,0x8(%esp)
  8017cd:	89 44 24 04          	mov    %eax,0x4(%esp)
  8017d1:	c7 04 24 38 34 80 00 	movl   $0x803438,(%esp)
  8017d8:	e8 40 eb ff ff       	call   80031d <cprintf>
	*dev = 0;
  8017dd:	c7 03 00 00 00 00    	movl   $0x0,(%ebx)
  8017e3:	b8 fd ff ff ff       	mov    $0xfffffffd,%eax
	return -E_INVAL;
}
  8017e8:	83 c4 10             	add    $0x10,%esp
  8017eb:	5b                   	pop    %ebx
  8017ec:	5e                   	pop    %esi
  8017ed:	5d                   	pop    %ebp
  8017ee:	c3                   	ret    

008017ef <fstat>:
	return (*dev->dev_trunc)(fd, newsize);
}

int
fstat(int fdnum, struct Stat *stat)
{
  8017ef:	55                   	push   %ebp
  8017f0:	89 e5                	mov    %esp,%ebp
  8017f2:	53                   	push   %ebx
  8017f3:	83 ec 24             	sub    $0x24,%esp
  8017f6:	8b 5d 0c             	mov    0xc(%ebp),%ebx
	int r;
	struct Dev *dev;
	struct Fd *fd;

	if ((r = fd_lookup(fdnum, &fd)) < 0
  8017f9:	8d 45 f0             	lea    -0x10(%ebp),%eax
  8017fc:	89 44 24 04          	mov    %eax,0x4(%esp)
  801800:	8b 45 08             	mov    0x8(%ebp),%eax
  801803:	89 04 24             	mov    %eax,(%esp)
  801806:	e8 02 ff ff ff       	call   80170d <fd_lookup>
  80180b:	85 c0                	test   %eax,%eax
  80180d:	78 53                	js     801862 <fstat+0x73>
	    || (r = dev_lookup(fd->fd_dev_id, &dev)) < 0)
  80180f:	8d 45 f4             	lea    -0xc(%ebp),%eax
  801812:	89 44 24 04          	mov    %eax,0x4(%esp)
  801816:	8b 45 f0             	mov    -0x10(%ebp),%eax
  801819:	8b 00                	mov    (%eax),%eax
  80181b:	89 04 24             	mov    %eax,(%esp)
  80181e:	e8 5e ff ff ff       	call   801781 <dev_lookup>
{
	int r;
	struct Dev *dev;
	struct Fd *fd;

	if ((r = fd_lookup(fdnum, &fd)) < 0
  801823:	85 c0                	test   %eax,%eax
  801825:	78 3b                	js     801862 <fstat+0x73>
	    || (r = dev_lookup(fd->fd_dev_id, &dev)) < 0)
		return r;
	if (!dev->dev_stat)
  801827:	b8 f1 ff ff ff       	mov    $0xfffffff1,%eax
  80182c:	8b 55 f4             	mov    -0xc(%ebp),%edx
  80182f:	83 7a 14 00          	cmpl   $0x0,0x14(%edx)
  801833:	74 2d                	je     801862 <fstat+0x73>
		return -E_NOT_SUPP;
	stat->st_name[0] = 0;
  801835:	c6 03 00             	movb   $0x0,(%ebx)
	stat->st_size = 0;
  801838:	c7 83 80 00 00 00 00 	movl   $0x0,0x80(%ebx)
  80183f:	00 00 00 
	stat->st_isdir = 0;
  801842:	c7 83 84 00 00 00 00 	movl   $0x0,0x84(%ebx)
  801849:	00 00 00 
	stat->st_dev = dev;
  80184c:	8b 45 f4             	mov    -0xc(%ebp),%eax
  80184f:	89 83 88 00 00 00    	mov    %eax,0x88(%ebx)
	return (*dev->dev_stat)(fd, stat);
  801855:	89 5c 24 04          	mov    %ebx,0x4(%esp)
  801859:	8b 55 f0             	mov    -0x10(%ebp),%edx
  80185c:	89 14 24             	mov    %edx,(%esp)
  80185f:	ff 50 14             	call   *0x14(%eax)
}
  801862:	83 c4 24             	add    $0x24,%esp
  801865:	5b                   	pop    %ebx
  801866:	5d                   	pop    %ebp
  801867:	c3                   	ret    

00801868 <ftruncate>:
	return 0;
}

int
ftruncate(int fdnum, off_t newsize)
{
  801868:	55                   	push   %ebp
  801869:	89 e5                	mov    %esp,%ebp
  80186b:	53                   	push   %ebx
  80186c:	83 ec 24             	sub    $0x24,%esp
  80186f:	8b 5d 08             	mov    0x8(%ebp),%ebx
	int r;
	struct Dev *dev;
	struct Fd *fd;
	if ((r = fd_lookup(fdnum, &fd)) < 0
  801872:	8d 45 f0             	lea    -0x10(%ebp),%eax
  801875:	89 44 24 04          	mov    %eax,0x4(%esp)
  801879:	89 1c 24             	mov    %ebx,(%esp)
  80187c:	e8 8c fe ff ff       	call   80170d <fd_lookup>
  801881:	85 c0                	test   %eax,%eax
  801883:	78 5f                	js     8018e4 <ftruncate+0x7c>
	    || (r = dev_lookup(fd->fd_dev_id, &dev)) < 0)
  801885:	8d 45 f4             	lea    -0xc(%ebp),%eax
  801888:	89 44 24 04          	mov    %eax,0x4(%esp)
  80188c:	8b 45 f0             	mov    -0x10(%ebp),%eax
  80188f:	8b 00                	mov    (%eax),%eax
  801891:	89 04 24             	mov    %eax,(%esp)
  801894:	e8 e8 fe ff ff       	call   801781 <dev_lookup>
ftruncate(int fdnum, off_t newsize)
{
	int r;
	struct Dev *dev;
	struct Fd *fd;
	if ((r = fd_lookup(fdnum, &fd)) < 0
  801899:	85 c0                	test   %eax,%eax
  80189b:	78 47                	js     8018e4 <ftruncate+0x7c>
	    || (r = dev_lookup(fd->fd_dev_id, &dev)) < 0)
		return r;
	if ((fd->fd_omode & O_ACCMODE) == O_RDONLY) {
  80189d:	8b 55 f0             	mov    -0x10(%ebp),%edx
  8018a0:	f6 42 08 03          	testb  $0x3,0x8(%edx)
  8018a4:	75 23                	jne    8018c9 <ftruncate+0x61>
		cprintf("[%08x] ftruncate %d -- bad mode\n",
			env->env_id, fdnum); 
  8018a6:	a1 74 70 80 00       	mov    0x807074,%eax
	struct Fd *fd;
	if ((r = fd_lookup(fdnum, &fd)) < 0
	    || (r = dev_lookup(fd->fd_dev_id, &dev)) < 0)
		return r;
	if ((fd->fd_omode & O_ACCMODE) == O_RDONLY) {
		cprintf("[%08x] ftruncate %d -- bad mode\n",
  8018ab:	8b 40 4c             	mov    0x4c(%eax),%eax
  8018ae:	89 5c 24 08          	mov    %ebx,0x8(%esp)
  8018b2:	89 44 24 04          	mov    %eax,0x4(%esp)
  8018b6:	c7 04 24 58 34 80 00 	movl   $0x803458,(%esp)
  8018bd:	e8 5b ea ff ff       	call   80031d <cprintf>
  8018c2:	b8 fd ff ff ff       	mov    $0xfffffffd,%eax
			env->env_id, fdnum); 
		return -E_INVAL;
  8018c7:	eb 1b                	jmp    8018e4 <ftruncate+0x7c>
	}
	if (!dev->dev_trunc)
  8018c9:	8b 45 f4             	mov    -0xc(%ebp),%eax
  8018cc:	8b 48 18             	mov    0x18(%eax),%ecx
  8018cf:	b8 f1 ff ff ff       	mov    $0xfffffff1,%eax
  8018d4:	85 c9                	test   %ecx,%ecx
  8018d6:	74 0c                	je     8018e4 <ftruncate+0x7c>
		return -E_NOT_SUPP;
	return (*dev->dev_trunc)(fd, newsize);
  8018d8:	8b 45 0c             	mov    0xc(%ebp),%eax
  8018db:	89 44 24 04          	mov    %eax,0x4(%esp)
  8018df:	89 14 24             	mov    %edx,(%esp)
  8018e2:	ff d1                	call   *%ecx
}
  8018e4:	83 c4 24             	add    $0x24,%esp
  8018e7:	5b                   	pop    %ebx
  8018e8:	5d                   	pop    %ebp
  8018e9:	c3                   	ret    

008018ea <write>:
	return tot;
}

ssize_t
write(int fdnum, const void *buf, size_t n)
{
  8018ea:	55                   	push   %ebp
  8018eb:	89 e5                	mov    %esp,%ebp
  8018ed:	53                   	push   %ebx
  8018ee:	83 ec 24             	sub    $0x24,%esp
  8018f1:	8b 5d 08             	mov    0x8(%ebp),%ebx
	int r;
	struct Dev *dev;
	struct Fd *fd;

	if ((r = fd_lookup(fdnum, &fd)) < 0
  8018f4:	8d 45 f0             	lea    -0x10(%ebp),%eax
  8018f7:	89 44 24 04          	mov    %eax,0x4(%esp)
  8018fb:	89 1c 24             	mov    %ebx,(%esp)
  8018fe:	e8 0a fe ff ff       	call   80170d <fd_lookup>
  801903:	85 c0                	test   %eax,%eax
  801905:	78 66                	js     80196d <write+0x83>
	    || (r = dev_lookup(fd->fd_dev_id, &dev)) < 0)
  801907:	8d 45 f4             	lea    -0xc(%ebp),%eax
  80190a:	89 44 24 04          	mov    %eax,0x4(%esp)
  80190e:	8b 45 f0             	mov    -0x10(%ebp),%eax
  801911:	8b 00                	mov    (%eax),%eax
  801913:	89 04 24             	mov    %eax,(%esp)
  801916:	e8 66 fe ff ff       	call   801781 <dev_lookup>
{
	int r;
	struct Dev *dev;
	struct Fd *fd;

	if ((r = fd_lookup(fdnum, &fd)) < 0
  80191b:	85 c0                	test   %eax,%eax
  80191d:	78 4e                	js     80196d <write+0x83>
	    || (r = dev_lookup(fd->fd_dev_id, &dev)) < 0)
		return r;
	if ((fd->fd_omode & O_ACCMODE) == O_RDONLY) {
  80191f:	8b 55 f0             	mov    -0x10(%ebp),%edx
  801922:	f6 42 08 03          	testb  $0x3,0x8(%edx)
  801926:	75 23                	jne    80194b <write+0x61>
		cprintf("[%08x] write %d -- bad mode\n", env->env_id, fdnum);
  801928:	a1 74 70 80 00       	mov    0x807074,%eax
  80192d:	8b 40 4c             	mov    0x4c(%eax),%eax
  801930:	89 5c 24 08          	mov    %ebx,0x8(%esp)
  801934:	89 44 24 04          	mov    %eax,0x4(%esp)
  801938:	c7 04 24 79 34 80 00 	movl   $0x803479,(%esp)
  80193f:	e8 d9 e9 ff ff       	call   80031d <cprintf>
  801944:	b8 fd ff ff ff       	mov    $0xfffffffd,%eax
		return -E_INVAL;
  801949:	eb 22                	jmp    80196d <write+0x83>
	}
	if (debug)
		cprintf("write %d %p %d via dev %s\n",
			fdnum, buf, n, dev->dev_name);
	if (!dev->dev_write)
  80194b:	8b 45 f4             	mov    -0xc(%ebp),%eax
  80194e:	8b 48 0c             	mov    0xc(%eax),%ecx
  801951:	b8 f1 ff ff ff       	mov    $0xfffffff1,%eax
  801956:	85 c9                	test   %ecx,%ecx
  801958:	74 13                	je     80196d <write+0x83>
		return -E_NOT_SUPP;
	return (*dev->dev_write)(fd, buf, n);
  80195a:	8b 45 10             	mov    0x10(%ebp),%eax
  80195d:	89 44 24 08          	mov    %eax,0x8(%esp)
  801961:	8b 45 0c             	mov    0xc(%ebp),%eax
  801964:	89 44 24 04          	mov    %eax,0x4(%esp)
  801968:	89 14 24             	mov    %edx,(%esp)
  80196b:	ff d1                	call   *%ecx
}
  80196d:	83 c4 24             	add    $0x24,%esp
  801970:	5b                   	pop    %ebx
  801971:	5d                   	pop    %ebp
  801972:	c3                   	ret    

00801973 <read>:
	return r;
}

ssize_t
read(int fdnum, void *buf, size_t n)
{
  801973:	55                   	push   %ebp
  801974:	89 e5                	mov    %esp,%ebp
  801976:	57                   	push   %edi
  801977:	56                   	push   %esi
  801978:	53                   	push   %ebx
  801979:	83 ec 2c             	sub    $0x2c,%esp
  80197c:	8b 5d 08             	mov    0x8(%ebp),%ebx
  80197f:	8b 75 10             	mov    0x10(%ebp),%esi
	int r;
	int m, tot;
	struct Dev *dev;
	struct Fd *fd;

	if ((r = fd_lookup(fdnum, &fd)) < 0
  801982:	8d 45 e0             	lea    -0x20(%ebp),%eax
  801985:	89 44 24 04          	mov    %eax,0x4(%esp)
  801989:	89 1c 24             	mov    %ebx,(%esp)
  80198c:	e8 7c fd ff ff       	call   80170d <fd_lookup>
  801991:	85 c0                	test   %eax,%eax
  801993:	0f 88 b0 00 00 00    	js     801a49 <read+0xd6>
	    || (r = dev_lookup(fd->fd_dev_id, &dev)) < 0)
  801999:	8d 45 e4             	lea    -0x1c(%ebp),%eax
  80199c:	89 44 24 04          	mov    %eax,0x4(%esp)
  8019a0:	8b 45 e0             	mov    -0x20(%ebp),%eax
  8019a3:	8b 00                	mov    (%eax),%eax
  8019a5:	89 04 24             	mov    %eax,(%esp)
  8019a8:	e8 d4 fd ff ff       	call   801781 <dev_lookup>
	int r;
	int m, tot;
	struct Dev *dev;
	struct Fd *fd;

	if ((r = fd_lookup(fdnum, &fd)) < 0
  8019ad:	85 c0                	test   %eax,%eax
  8019af:	0f 88 94 00 00 00    	js     801a49 <read+0xd6>
	    || (r = dev_lookup(fd->fd_dev_id, &dev)) < 0)
		return r;
	if ((fd->fd_omode & O_ACCMODE) == O_WRONLY) {
  8019b5:	8b 45 e0             	mov    -0x20(%ebp),%eax
  8019b8:	8b 40 08             	mov    0x8(%eax),%eax
  8019bb:	83 e0 03             	and    $0x3,%eax
  8019be:	83 f8 01             	cmp    $0x1,%eax
  8019c1:	75 23                	jne    8019e6 <read+0x73>
		cprintf("[%08x] read %d -- bad mode\n", env->env_id, fdnum); 
  8019c3:	a1 74 70 80 00       	mov    0x807074,%eax
  8019c8:	8b 40 4c             	mov    0x4c(%eax),%eax
  8019cb:	89 5c 24 08          	mov    %ebx,0x8(%esp)
  8019cf:	89 44 24 04          	mov    %eax,0x4(%esp)
  8019d3:	c7 04 24 96 34 80 00 	movl   $0x803496,(%esp)
  8019da:	e8 3e e9 ff ff       	call   80031d <cprintf>
  8019df:	b8 fd ff ff ff       	mov    $0xfffffffd,%eax
		return -E_INVAL;
  8019e4:	eb 63                	jmp    801a49 <read+0xd6>
	}
	if (!dev->dev_read)
  8019e6:	b8 f1 ff ff ff       	mov    $0xfffffff1,%eax
  8019eb:	8b 55 e4             	mov    -0x1c(%ebp),%edx
  8019ee:	83 7a 08 00          	cmpl   $0x0,0x8(%edx)
  8019f2:	74 55                	je     801a49 <read+0xd6>
		return -E_NOT_SUPP;

  for (tot = 0; tot < n; tot += m) {
  8019f4:	ba 00 00 00 00       	mov    $0x0,%edx
  8019f9:	bb 00 00 00 00       	mov    $0x0,%ebx
  8019fe:	b8 00 00 00 00       	mov    $0x0,%eax
  801a03:	85 f6                	test   %esi,%esi
  801a05:	74 42                	je     801a49 <read+0xd6>
    int count=0;
    if ((n-tot)/PGSIZE == 0)
  801a07:	bf 00 10 00 00       	mov    $0x1000,%edi
  801a0c:	89 f0                	mov    %esi,%eax
  801a0e:	29 d0                	sub    %edx,%eax
  801a10:	89 c1                	mov    %eax,%ecx
  801a12:	81 e1 ff 0f 00 00    	and    $0xfff,%ecx
  801a18:	3d 00 10 00 00       	cmp    $0x1000,%eax
  801a1d:	0f 43 cf             	cmovae %edi,%ecx
      count = (n-tot)%PGSIZE;
    else
      count = PGSIZE;

	  m = (*dev->dev_read)(fd, (char *)buf + tot, count);
  801a20:	89 4c 24 08          	mov    %ecx,0x8(%esp)
  801a24:	03 55 0c             	add    0xc(%ebp),%edx
  801a27:	89 54 24 04          	mov    %edx,0x4(%esp)
  801a2b:	8b 45 e0             	mov    -0x20(%ebp),%eax
  801a2e:	89 04 24             	mov    %eax,(%esp)
  801a31:	8b 45 e4             	mov    -0x1c(%ebp),%eax
  801a34:	ff 50 08             	call   *0x8(%eax)
		if (m < 0)
  801a37:	85 c0                	test   %eax,%eax
  801a39:	78 0e                	js     801a49 <read+0xd6>
			return m;
		if (m == 0)
  801a3b:	85 c0                	test   %eax,%eax
  801a3d:	74 08                	je     801a47 <read+0xd4>
		return -E_INVAL;
	}
	if (!dev->dev_read)
		return -E_NOT_SUPP;

  for (tot = 0; tot < n; tot += m) {
  801a3f:	01 c3                	add    %eax,%ebx
  801a41:	89 da                	mov    %ebx,%edx
  801a43:	39 f3                	cmp    %esi,%ebx
  801a45:	72 c5                	jb     801a0c <read+0x99>
  801a47:	89 d8                	mov    %ebx,%eax
			return m;
		if (m == 0)
			break;
	}
	return tot;
}
  801a49:	83 c4 2c             	add    $0x2c,%esp
  801a4c:	5b                   	pop    %ebx
  801a4d:	5e                   	pop    %esi
  801a4e:	5f                   	pop    %edi
  801a4f:	5d                   	pop    %ebp
  801a50:	c3                   	ret    

00801a51 <readn>:

ssize_t
readn(int fdnum, void *buf, size_t n)
{
  801a51:	55                   	push   %ebp
  801a52:	89 e5                	mov    %esp,%ebp
  801a54:	57                   	push   %edi
  801a55:	56                   	push   %esi
  801a56:	53                   	push   %ebx
  801a57:	83 ec 1c             	sub    $0x1c,%esp
  801a5a:	8b 7d 08             	mov    0x8(%ebp),%edi
  801a5d:	8b 75 10             	mov    0x10(%ebp),%esi
	int m, tot;
  struct Fd *fd = INDEX2FD(fdnum);

	for (tot = 0; tot < n; tot += m) {
  801a60:	ba 00 00 00 00       	mov    $0x0,%edx
  801a65:	bb 00 00 00 00       	mov    $0x0,%ebx
  801a6a:	b8 00 00 00 00       	mov    $0x0,%eax
  801a6f:	85 f6                	test   %esi,%esi
  801a71:	74 29                	je     801a9c <readn+0x4b>
		m = read(fdnum, (char*)buf + tot, n - tot);
  801a73:	89 f0                	mov    %esi,%eax
  801a75:	29 d0                	sub    %edx,%eax
  801a77:	89 44 24 08          	mov    %eax,0x8(%esp)
  801a7b:	03 55 0c             	add    0xc(%ebp),%edx
  801a7e:	89 54 24 04          	mov    %edx,0x4(%esp)
  801a82:	89 3c 24             	mov    %edi,(%esp)
  801a85:	e8 e9 fe ff ff       	call   801973 <read>
		if (m < 0)
  801a8a:	85 c0                	test   %eax,%eax
  801a8c:	78 0e                	js     801a9c <readn+0x4b>
			return m;
		if (m == 0)
  801a8e:	85 c0                	test   %eax,%eax
  801a90:	74 08                	je     801a9a <readn+0x49>
readn(int fdnum, void *buf, size_t n)
{
	int m, tot;
  struct Fd *fd = INDEX2FD(fdnum);

	for (tot = 0; tot < n; tot += m) {
  801a92:	01 c3                	add    %eax,%ebx
  801a94:	89 da                	mov    %ebx,%edx
  801a96:	39 f3                	cmp    %esi,%ebx
  801a98:	72 d9                	jb     801a73 <readn+0x22>
  801a9a:	89 d8                	mov    %ebx,%eax
			return m;
		if (m == 0)
			break;
	}
	return tot;
}
  801a9c:	83 c4 1c             	add    $0x1c,%esp
  801a9f:	5b                   	pop    %ebx
  801aa0:	5e                   	pop    %esi
  801aa1:	5f                   	pop    %edi
  801aa2:	5d                   	pop    %ebp
  801aa3:	c3                   	ret    

00801aa4 <fd_close>:
// If 'must_exist' is 1, then fd_close returns -E_INVAL when passed a
// closed or nonexistent file descriptor.
// Returns 0 on success, < 0 on error.
int
fd_close(struct Fd *fd, bool must_exist)
{
  801aa4:	55                   	push   %ebp
  801aa5:	89 e5                	mov    %esp,%ebp
  801aa7:	83 ec 28             	sub    $0x28,%esp
  801aaa:	89 5d f8             	mov    %ebx,-0x8(%ebp)
  801aad:	89 75 fc             	mov    %esi,-0x4(%ebp)
  801ab0:	8b 75 08             	mov    0x8(%ebp),%esi
	struct Fd *fd2;
	struct Dev *dev;
	int r;
	if ((r = fd_lookup(fd2num(fd), &fd2)) < 0
  801ab3:	89 34 24             	mov    %esi,(%esp)
  801ab6:	e8 b5 fb ff ff       	call   801670 <fd2num>
  801abb:	8d 55 f4             	lea    -0xc(%ebp),%edx
  801abe:	89 54 24 04          	mov    %edx,0x4(%esp)
  801ac2:	89 04 24             	mov    %eax,(%esp)
  801ac5:	e8 43 fc ff ff       	call   80170d <fd_lookup>
  801aca:	89 c3                	mov    %eax,%ebx
  801acc:	85 c0                	test   %eax,%eax
  801ace:	78 05                	js     801ad5 <fd_close+0x31>
  801ad0:	3b 75 f4             	cmp    -0xc(%ebp),%esi
  801ad3:	74 0e                	je     801ae3 <fd_close+0x3f>
	    || fd != fd2)
		return (must_exist ? r : 0);
  801ad5:	83 7d 0c 00          	cmpl   $0x0,0xc(%ebp)
  801ad9:	b8 00 00 00 00       	mov    $0x0,%eax
  801ade:	0f 44 d8             	cmove  %eax,%ebx
  801ae1:	eb 3d                	jmp    801b20 <fd_close+0x7c>
	if ((r = dev_lookup(fd->fd_dev_id, &dev)) >= 0) {
  801ae3:	8d 45 f0             	lea    -0x10(%ebp),%eax
  801ae6:	89 44 24 04          	mov    %eax,0x4(%esp)
  801aea:	8b 06                	mov    (%esi),%eax
  801aec:	89 04 24             	mov    %eax,(%esp)
  801aef:	e8 8d fc ff ff       	call   801781 <dev_lookup>
  801af4:	89 c3                	mov    %eax,%ebx
  801af6:	85 c0                	test   %eax,%eax
  801af8:	78 16                	js     801b10 <fd_close+0x6c>
		if (dev->dev_close)
  801afa:	8b 45 f0             	mov    -0x10(%ebp),%eax
  801afd:	8b 40 10             	mov    0x10(%eax),%eax
  801b00:	bb 00 00 00 00       	mov    $0x0,%ebx
  801b05:	85 c0                	test   %eax,%eax
  801b07:	74 07                	je     801b10 <fd_close+0x6c>
			r = (*dev->dev_close)(fd);
  801b09:	89 34 24             	mov    %esi,(%esp)
  801b0c:	ff d0                	call   *%eax
  801b0e:	89 c3                	mov    %eax,%ebx
		else
			r = 0;
	}
	// Make sure fd is unmapped.  Might be a no-op if
	// (*dev->dev_close)(fd) already unmapped it.
	(void) sys_page_unmap(0, fd);
  801b10:	89 74 24 04          	mov    %esi,0x4(%esp)
  801b14:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  801b1b:	e8 6a f5 ff ff       	call   80108a <sys_page_unmap>
	return r;
}
  801b20:	89 d8                	mov    %ebx,%eax
  801b22:	8b 5d f8             	mov    -0x8(%ebp),%ebx
  801b25:	8b 75 fc             	mov    -0x4(%ebp),%esi
  801b28:	89 ec                	mov    %ebp,%esp
  801b2a:	5d                   	pop    %ebp
  801b2b:	c3                   	ret    

00801b2c <close>:
	return -E_INVAL;
}

int
close(int fdnum)
{
  801b2c:	55                   	push   %ebp
  801b2d:	89 e5                	mov    %esp,%ebp
  801b2f:	83 ec 28             	sub    $0x28,%esp
	struct Fd *fd;
	int r;

	if ((r = fd_lookup(fdnum, &fd)) < 0)
  801b32:	8d 45 f4             	lea    -0xc(%ebp),%eax
  801b35:	89 44 24 04          	mov    %eax,0x4(%esp)
  801b39:	8b 45 08             	mov    0x8(%ebp),%eax
  801b3c:	89 04 24             	mov    %eax,(%esp)
  801b3f:	e8 c9 fb ff ff       	call   80170d <fd_lookup>
  801b44:	85 c0                	test   %eax,%eax
  801b46:	78 13                	js     801b5b <close+0x2f>
		return r;
	else
		return fd_close(fd, 1);
  801b48:	c7 44 24 04 01 00 00 	movl   $0x1,0x4(%esp)
  801b4f:	00 
  801b50:	8b 45 f4             	mov    -0xc(%ebp),%eax
  801b53:	89 04 24             	mov    %eax,(%esp)
  801b56:	e8 49 ff ff ff       	call   801aa4 <fd_close>
}
  801b5b:	c9                   	leave  
  801b5c:	c3                   	ret    

00801b5d <stat>:
	return (*dev->dev_stat)(fd, stat);
}

int
stat(const char *path, struct Stat *stat)
{
  801b5d:	55                   	push   %ebp
  801b5e:	89 e5                	mov    %esp,%ebp
  801b60:	83 ec 18             	sub    $0x18,%esp
  801b63:	89 5d f8             	mov    %ebx,-0x8(%ebp)
  801b66:	89 75 fc             	mov    %esi,-0x4(%ebp)
	int fd, r;

	if ((fd = open(path, O_RDONLY)) < 0)
  801b69:	c7 44 24 04 00 00 00 	movl   $0x0,0x4(%esp)
  801b70:	00 
  801b71:	8b 45 08             	mov    0x8(%ebp),%eax
  801b74:	89 04 24             	mov    %eax,(%esp)
  801b77:	e8 80 03 00 00       	call   801efc <open>
  801b7c:	89 c3                	mov    %eax,%ebx
  801b7e:	85 c0                	test   %eax,%eax
  801b80:	78 1b                	js     801b9d <stat+0x40>
		return fd;
	r = fstat(fd, stat);
  801b82:	8b 45 0c             	mov    0xc(%ebp),%eax
  801b85:	89 44 24 04          	mov    %eax,0x4(%esp)
  801b89:	89 1c 24             	mov    %ebx,(%esp)
  801b8c:	e8 5e fc ff ff       	call   8017ef <fstat>
  801b91:	89 c6                	mov    %eax,%esi
	close(fd);
  801b93:	89 1c 24             	mov    %ebx,(%esp)
  801b96:	e8 91 ff ff ff       	call   801b2c <close>
  801b9b:	89 f3                	mov    %esi,%ebx
	return r;
}
  801b9d:	89 d8                	mov    %ebx,%eax
  801b9f:	8b 5d f8             	mov    -0x8(%ebp),%ebx
  801ba2:	8b 75 fc             	mov    -0x4(%ebp),%esi
  801ba5:	89 ec                	mov    %ebp,%esp
  801ba7:	5d                   	pop    %ebp
  801ba8:	c3                   	ret    

00801ba9 <close_all>:
		return fd_close(fd, 1);
}

void
close_all(void)
{
  801ba9:	55                   	push   %ebp
  801baa:	89 e5                	mov    %esp,%ebp
  801bac:	53                   	push   %ebx
  801bad:	83 ec 14             	sub    $0x14,%esp
  801bb0:	bb 00 00 00 00       	mov    $0x0,%ebx
	int i;
	for (i = 0; i < MAXFD; i++)
		close(i);
  801bb5:	89 1c 24             	mov    %ebx,(%esp)
  801bb8:	e8 6f ff ff ff       	call   801b2c <close>

void
close_all(void)
{
	int i;
	for (i = 0; i < MAXFD; i++)
  801bbd:	83 c3 01             	add    $0x1,%ebx
  801bc0:	83 fb 20             	cmp    $0x20,%ebx
  801bc3:	75 f0                	jne    801bb5 <close_all+0xc>
		close(i);
}
  801bc5:	83 c4 14             	add    $0x14,%esp
  801bc8:	5b                   	pop    %ebx
  801bc9:	5d                   	pop    %ebp
  801bca:	c3                   	ret    

00801bcb <dup>:
// file and the file offset of the other.
// Closes any previously open file descriptor at 'newfdnum'.
// This is implemented using virtual memory tricks (of course!).
int
dup(int oldfdnum, int newfdnum)
{
  801bcb:	55                   	push   %ebp
  801bcc:	89 e5                	mov    %esp,%ebp
  801bce:	83 ec 58             	sub    $0x58,%esp
  801bd1:	89 5d f4             	mov    %ebx,-0xc(%ebp)
  801bd4:	89 75 f8             	mov    %esi,-0x8(%ebp)
  801bd7:	89 7d fc             	mov    %edi,-0x4(%ebp)
  801bda:	8b 7d 0c             	mov    0xc(%ebp),%edi
	int r;
	char *ova, *nva;
	pte_t pte;
	struct Fd *oldfd, *newfd;

	if ((r = fd_lookup(oldfdnum, &oldfd)) < 0)
  801bdd:	8d 45 e4             	lea    -0x1c(%ebp),%eax
  801be0:	89 44 24 04          	mov    %eax,0x4(%esp)
  801be4:	8b 45 08             	mov    0x8(%ebp),%eax
  801be7:	89 04 24             	mov    %eax,(%esp)
  801bea:	e8 1e fb ff ff       	call   80170d <fd_lookup>
  801bef:	89 c3                	mov    %eax,%ebx
  801bf1:	85 c0                	test   %eax,%eax
  801bf3:	0f 88 e0 00 00 00    	js     801cd9 <dup+0x10e>
		return r;
	close(newfdnum);
  801bf9:	89 3c 24             	mov    %edi,(%esp)
  801bfc:	e8 2b ff ff ff       	call   801b2c <close>

	newfd = INDEX2FD(newfdnum);
  801c01:	8d b7 00 00 0d 00    	lea    0xd0000(%edi),%esi
  801c07:	c1 e6 0c             	shl    $0xc,%esi
	ova = fd2data(oldfd);
  801c0a:	8b 45 e4             	mov    -0x1c(%ebp),%eax
  801c0d:	89 04 24             	mov    %eax,(%esp)
  801c10:	e8 6b fa ff ff       	call   801680 <fd2data>
  801c15:	89 c3                	mov    %eax,%ebx
	nva = fd2data(newfd);
  801c17:	89 34 24             	mov    %esi,(%esp)
  801c1a:	e8 61 fa ff ff       	call   801680 <fd2data>
  801c1f:	89 45 d4             	mov    %eax,-0x2c(%ebp)
	if ((vpd[PDX(ova)] & PTE_P) && (vpt[VPN(ova)] & PTE_P))
  801c22:	89 da                	mov    %ebx,%edx
  801c24:	89 d8                	mov    %ebx,%eax
  801c26:	c1 e8 16             	shr    $0x16,%eax
  801c29:	8b 04 85 00 d0 7b ef 	mov    -0x10843000(,%eax,4),%eax
  801c30:	a8 01                	test   $0x1,%al
  801c32:	74 43                	je     801c77 <dup+0xac>
  801c34:	c1 ea 0c             	shr    $0xc,%edx
  801c37:	8b 04 95 00 00 40 ef 	mov    -0x10c00000(,%edx,4),%eax
  801c3e:	a8 01                	test   $0x1,%al
  801c40:	74 35                	je     801c77 <dup+0xac>
		if ((r = sys_page_map(0, ova, 0, nva, (vpt[VPN(ova)]) & PTE_USER)) < 0)
  801c42:	8b 04 95 00 00 40 ef 	mov    -0x10c00000(,%edx,4),%eax
  801c49:	25 07 0e 00 00       	and    $0xe07,%eax
  801c4e:	89 44 24 10          	mov    %eax,0x10(%esp)
  801c52:	8b 45 d4             	mov    -0x2c(%ebp),%eax
  801c55:	89 44 24 0c          	mov    %eax,0xc(%esp)
  801c59:	c7 44 24 08 00 00 00 	movl   $0x0,0x8(%esp)
  801c60:	00 
  801c61:	89 5c 24 04          	mov    %ebx,0x4(%esp)
  801c65:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  801c6c:	e8 77 f4 ff ff       	call   8010e8 <sys_page_map>
  801c71:	89 c3                	mov    %eax,%ebx
  801c73:	85 c0                	test   %eax,%eax
  801c75:	78 3f                	js     801cb6 <dup+0xeb>
			goto err;
	if ((r = sys_page_map(0, oldfd, 0, newfd, (vpt[VPN(oldfd)]) & PTE_USER)) < 0)
  801c77:	8b 45 e4             	mov    -0x1c(%ebp),%eax
  801c7a:	89 c2                	mov    %eax,%edx
  801c7c:	c1 ea 0c             	shr    $0xc,%edx
  801c7f:	8b 14 95 00 00 40 ef 	mov    -0x10c00000(,%edx,4),%edx
  801c86:	81 e2 07 0e 00 00    	and    $0xe07,%edx
  801c8c:	89 54 24 10          	mov    %edx,0x10(%esp)
  801c90:	89 74 24 0c          	mov    %esi,0xc(%esp)
  801c94:	c7 44 24 08 00 00 00 	movl   $0x0,0x8(%esp)
  801c9b:	00 
  801c9c:	89 44 24 04          	mov    %eax,0x4(%esp)
  801ca0:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  801ca7:	e8 3c f4 ff ff       	call   8010e8 <sys_page_map>
  801cac:	89 c3                	mov    %eax,%ebx
  801cae:	85 c0                	test   %eax,%eax
  801cb0:	78 04                	js     801cb6 <dup+0xeb>
  801cb2:	89 fb                	mov    %edi,%ebx
  801cb4:	eb 23                	jmp    801cd9 <dup+0x10e>
		goto err;

	return newfdnum;
err:
	sys_page_unmap(0, newfd);
  801cb6:	89 74 24 04          	mov    %esi,0x4(%esp)
  801cba:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  801cc1:	e8 c4 f3 ff ff       	call   80108a <sys_page_unmap>
	sys_page_unmap(0, nva);
  801cc6:	8b 45 d4             	mov    -0x2c(%ebp),%eax
  801cc9:	89 44 24 04          	mov    %eax,0x4(%esp)
  801ccd:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  801cd4:	e8 b1 f3 ff ff       	call   80108a <sys_page_unmap>
	return r;
}
  801cd9:	89 d8                	mov    %ebx,%eax
  801cdb:	8b 5d f4             	mov    -0xc(%ebp),%ebx
  801cde:	8b 75 f8             	mov    -0x8(%ebp),%esi
  801ce1:	8b 7d fc             	mov    -0x4(%ebp),%edi
  801ce4:	89 ec                	mov    %ebp,%esp
  801ce6:	5d                   	pop    %ebp
  801ce7:	c3                   	ret    

00801ce8 <fsipc>:
// type: request code, passed as the simple integer IPC value.
// dstva: virtual address at which to receive reply page, 0 if none.
// Returns result from the file server.
static int
fsipc(unsigned type, void *dstva)
{
  801ce8:	55                   	push   %ebp
  801ce9:	89 e5                	mov    %esp,%ebp
  801ceb:	53                   	push   %ebx
  801cec:	83 ec 14             	sub    $0x14,%esp
  801cef:	89 d3                	mov    %edx,%ebx
	if (debug)
		cprintf("[%08x] fsipc %d %08x\n", env->env_id, type, *(uint32_t *)&fsipcbuf);

	ipc_send(envs[1].env_id, type, &fsipcbuf, PTE_P | PTE_W | PTE_U);
  801cf1:	8b 15 c8 00 c0 ee    	mov    0xeec000c8,%edx
  801cf7:	c7 44 24 0c 07 00 00 	movl   $0x7,0xc(%esp)
  801cfe:	00 
  801cff:	c7 44 24 08 00 40 80 	movl   $0x804000,0x8(%esp)
  801d06:	00 
  801d07:	89 44 24 04          	mov    %eax,0x4(%esp)
  801d0b:	89 14 24             	mov    %edx,(%esp)
  801d0e:	e8 8d 0d 00 00       	call   802aa0 <ipc_send>
	return ipc_recv(NULL, dstva, NULL);
  801d13:	c7 44 24 08 00 00 00 	movl   $0x0,0x8(%esp)
  801d1a:	00 
  801d1b:	89 5c 24 04          	mov    %ebx,0x4(%esp)
  801d1f:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  801d26:	e8 e7 0d 00 00       	call   802b12 <ipc_recv>
}
  801d2b:	83 c4 14             	add    $0x14,%esp
  801d2e:	5b                   	pop    %ebx
  801d2f:	5d                   	pop    %ebp
  801d30:	c3                   	ret    

00801d31 <devfile_trunc>:
}

// Truncate or extend an open file to 'size' bytes
static int
devfile_trunc(struct Fd *fd, off_t newsize)
{
  801d31:	55                   	push   %ebp
  801d32:	89 e5                	mov    %esp,%ebp
  801d34:	83 ec 08             	sub    $0x8,%esp
	fsipcbuf.set_size.req_fileid = fd->fd_file.id;
  801d37:	8b 45 08             	mov    0x8(%ebp),%eax
  801d3a:	8b 40 0c             	mov    0xc(%eax),%eax
  801d3d:	a3 00 40 80 00       	mov    %eax,0x804000
	fsipcbuf.set_size.req_size = newsize;
  801d42:	8b 45 0c             	mov    0xc(%ebp),%eax
  801d45:	a3 04 40 80 00       	mov    %eax,0x804004
	return fsipc(FSREQ_SET_SIZE, NULL);
  801d4a:	ba 00 00 00 00       	mov    $0x0,%edx
  801d4f:	b8 02 00 00 00       	mov    $0x2,%eax
  801d54:	e8 8f ff ff ff       	call   801ce8 <fsipc>
}
  801d59:	c9                   	leave  
  801d5a:	c3                   	ret    

00801d5b <devfile_flush>:
// open, unmapping it is enough to free up server-side resources.
// Other than that, we just have to make sure our changes are flushed
// to disk.
static int
devfile_flush(struct Fd *fd)
{
  801d5b:	55                   	push   %ebp
  801d5c:	89 e5                	mov    %esp,%ebp
  801d5e:	83 ec 08             	sub    $0x8,%esp
	fsipcbuf.flush.req_fileid = fd->fd_file.id;
  801d61:	8b 45 08             	mov    0x8(%ebp),%eax
  801d64:	8b 40 0c             	mov    0xc(%eax),%eax
  801d67:	a3 00 40 80 00       	mov    %eax,0x804000
	return fsipc(FSREQ_FLUSH, NULL);
  801d6c:	ba 00 00 00 00       	mov    $0x0,%edx
  801d71:	b8 06 00 00 00       	mov    $0x6,%eax
  801d76:	e8 6d ff ff ff       	call   801ce8 <fsipc>
}
  801d7b:	c9                   	leave  
  801d7c:	c3                   	ret    

00801d7d <sync>:
}

// Synchronize disk with buffer cache
int
sync(void)
{
  801d7d:	55                   	push   %ebp
  801d7e:	89 e5                	mov    %esp,%ebp
  801d80:	83 ec 08             	sub    $0x8,%esp
	// Ask the file server to update the disk
	// by writing any dirty blocks in the buffer cache.

	return fsipc(FSREQ_SYNC, NULL);
  801d83:	ba 00 00 00 00       	mov    $0x0,%edx
  801d88:	b8 08 00 00 00       	mov    $0x8,%eax
  801d8d:	e8 56 ff ff ff       	call   801ce8 <fsipc>
}
  801d92:	c9                   	leave  
  801d93:	c3                   	ret    

00801d94 <devfile_stat>:
    return n;
}

static int
devfile_stat(struct Fd *fd, struct Stat *st)
{
  801d94:	55                   	push   %ebp
  801d95:	89 e5                	mov    %esp,%ebp
  801d97:	53                   	push   %ebx
  801d98:	83 ec 14             	sub    $0x14,%esp
  801d9b:	8b 5d 0c             	mov    0xc(%ebp),%ebx
	int r;

	fsipcbuf.stat.req_fileid = fd->fd_file.id;
  801d9e:	8b 45 08             	mov    0x8(%ebp),%eax
  801da1:	8b 40 0c             	mov    0xc(%eax),%eax
  801da4:	a3 00 40 80 00       	mov    %eax,0x804000
	if ((r = fsipc(FSREQ_STAT, NULL)) < 0)
  801da9:	ba 00 00 00 00       	mov    $0x0,%edx
  801dae:	b8 05 00 00 00       	mov    $0x5,%eax
  801db3:	e8 30 ff ff ff       	call   801ce8 <fsipc>
  801db8:	85 c0                	test   %eax,%eax
  801dba:	78 2b                	js     801de7 <devfile_stat+0x53>
		return r;
	strcpy(st->st_name, fsipcbuf.statRet.ret_name);
  801dbc:	c7 44 24 04 00 40 80 	movl   $0x804000,0x4(%esp)
  801dc3:	00 
  801dc4:	89 1c 24             	mov    %ebx,(%esp)
  801dc7:	e8 1e ec ff ff       	call   8009ea <strcpy>
	st->st_size = fsipcbuf.statRet.ret_size;
  801dcc:	a1 80 40 80 00       	mov    0x804080,%eax
  801dd1:	89 83 80 00 00 00    	mov    %eax,0x80(%ebx)
	st->st_isdir = fsipcbuf.statRet.ret_isdir;
  801dd7:	a1 84 40 80 00       	mov    0x804084,%eax
  801ddc:	89 83 84 00 00 00    	mov    %eax,0x84(%ebx)
  801de2:	b8 00 00 00 00       	mov    $0x0,%eax
	return 0;
}
  801de7:	83 c4 14             	add    $0x14,%esp
  801dea:	5b                   	pop    %ebx
  801deb:	5d                   	pop    %ebp
  801dec:	c3                   	ret    

00801ded <devfile_write>:
// Returns:
//	 The number of bytes successfully written.
//	 < 0 on error.
static ssize_t
devfile_write(struct Fd *fd, const void *buf, size_t n)
{
  801ded:	55                   	push   %ebp
  801dee:	89 e5                	mov    %esp,%ebp
  801df0:	53                   	push   %ebx
  801df1:	83 ec 14             	sub    $0x14,%esp
  801df4:	8b 45 08             	mov    0x8(%ebp),%eax
  801df7:	8b 55 0c             	mov    0xc(%ebp),%edx
  801dfa:	8b 5d 10             	mov    0x10(%ebp),%ebx
	// careful: fsipcbuf.write.req_buf is only so large, but
	// remember that write is always allowed to write *fewer*
	// bytes than requested.
	// LAB 5: Your code here
    int r;
    if (!fd || !buf || (n>(PGSIZE-sizeof(size_t)-sizeof(int))))
  801dfd:	85 c0                	test   %eax,%eax
  801dff:	74 44                	je     801e45 <devfile_write+0x58>
  801e01:	85 d2                	test   %edx,%edx
  801e03:	74 40                	je     801e45 <devfile_write+0x58>
  801e05:	81 fb f8 0f 00 00    	cmp    $0xff8,%ebx
  801e0b:	77 38                	ja     801e45 <devfile_write+0x58>
        return -E_INVAL;

    fsipcbuf.write.req_fileid   = fd->fd_file.id;
  801e0d:	8b 40 0c             	mov    0xc(%eax),%eax
  801e10:	a3 00 40 80 00       	mov    %eax,0x804000
    fsipcbuf.write.req_n        = n;
  801e15:	89 1d 04 40 80 00    	mov    %ebx,0x804004
    memmove(fsipcbuf.write.req_buf, buf, n);
  801e1b:	89 5c 24 08          	mov    %ebx,0x8(%esp)
  801e1f:	89 54 24 04          	mov    %edx,0x4(%esp)
  801e23:	c7 04 24 08 40 80 00 	movl   $0x804008,(%esp)
  801e2a:	e8 76 ed ff ff       	call   800ba5 <memmove>
    if ((r=fsipc(FSREQ_WRITE, NULL))<0)
  801e2f:	ba 00 00 00 00       	mov    $0x0,%edx
  801e34:	b8 04 00 00 00       	mov    $0x4,%eax
  801e39:	e8 aa fe ff ff       	call   801ce8 <fsipc>
        return r;
    return n;
  801e3e:	85 c0                	test   %eax,%eax
  801e40:	0f 49 c3             	cmovns %ebx,%eax
  801e43:	eb 05                	jmp    801e4a <devfile_write+0x5d>
  801e45:	b8 fd ff ff ff       	mov    $0xfffffffd,%eax
}
  801e4a:	83 c4 14             	add    $0x14,%esp
  801e4d:	5b                   	pop    %ebx
  801e4e:	5d                   	pop    %ebp
  801e4f:	c3                   	ret    

00801e50 <devfile_read>:
// Returns:
// 	The number of bytes successfully read.
// 	< 0 on error.
static ssize_t
devfile_read(struct Fd *fd, void *buf, size_t n)
{
  801e50:	55                   	push   %ebp
  801e51:	89 e5                	mov    %esp,%ebp
  801e53:	83 ec 18             	sub    $0x18,%esp
  801e56:	89 5d f8             	mov    %ebx,-0x8(%ebp)
  801e59:	89 75 fc             	mov    %esi,-0x4(%ebp)
  801e5c:	8b 45 08             	mov    0x8(%ebp),%eax
  801e5f:	8b 75 0c             	mov    0xc(%ebp),%esi
	// filling fsipcbuf.read with the request arguments.  The
	// bytes read will be written back to fsipcbuf by the file
	// system server.
	// LAB 5: Your code here
  int r;
  if (!fd || !buf)
  801e62:	85 c0                	test   %eax,%eax
  801e64:	74 04                	je     801e6a <devfile_read+0x1a>
  801e66:	85 f6                	test   %esi,%esi
  801e68:	75 07                	jne    801e71 <devfile_read+0x21>
  801e6a:	bb fd ff ff ff       	mov    $0xfffffffd,%ebx
  801e6f:	eb 39                	jmp    801eaa <devfile_read+0x5a>
    return -E_INVAL;

  fsipcbuf.read.req_fileid    = fd->fd_file.id;
  801e71:	8b 40 0c             	mov    0xc(%eax),%eax
  801e74:	a3 00 40 80 00       	mov    %eax,0x804000
  fsipcbuf.read.req_n         = n;
  801e79:	8b 45 10             	mov    0x10(%ebp),%eax
  801e7c:	a3 04 40 80 00       	mov    %eax,0x804004
  if ((r=fsipc(FSREQ_READ, NULL))<0)
  801e81:	ba 00 00 00 00       	mov    $0x0,%edx
  801e86:	b8 03 00 00 00       	mov    $0x3,%eax
  801e8b:	e8 58 fe ff ff       	call   801ce8 <fsipc>
  801e90:	89 c3                	mov    %eax,%ebx
  801e92:	85 c0                	test   %eax,%eax
  801e94:	78 14                	js     801eaa <devfile_read+0x5a>
    return r;

  memmove(buf, fsipcbuf.readRet.ret_buf, r);
  801e96:	89 44 24 08          	mov    %eax,0x8(%esp)
  801e9a:	c7 44 24 04 00 40 80 	movl   $0x804000,0x4(%esp)
  801ea1:	00 
  801ea2:	89 34 24             	mov    %esi,(%esp)
  801ea5:	e8 fb ec ff ff       	call   800ba5 <memmove>
  return r;
}
  801eaa:	89 d8                	mov    %ebx,%eax
  801eac:	8b 5d f8             	mov    -0x8(%ebp),%ebx
  801eaf:	8b 75 fc             	mov    -0x4(%ebp),%esi
  801eb2:	89 ec                	mov    %ebp,%esp
  801eb4:	5d                   	pop    %ebp
  801eb5:	c3                   	ret    

00801eb6 <remove>:
}

// Delete a file
int
remove(const char *path)
{
  801eb6:	55                   	push   %ebp
  801eb7:	89 e5                	mov    %esp,%ebp
  801eb9:	53                   	push   %ebx
  801eba:	83 ec 14             	sub    $0x14,%esp
  801ebd:	8b 5d 08             	mov    0x8(%ebp),%ebx
	if (strlen(path) >= MAXPATHLEN)
  801ec0:	89 1c 24             	mov    %ebx,(%esp)
  801ec3:	e8 d8 ea ff ff       	call   8009a0 <strlen>
  801ec8:	89 c2                	mov    %eax,%edx
  801eca:	b8 f4 ff ff ff       	mov    $0xfffffff4,%eax
  801ecf:	81 fa ff 03 00 00    	cmp    $0x3ff,%edx
  801ed5:	7f 1f                	jg     801ef6 <remove+0x40>
		return -E_BAD_PATH;
	strcpy(fsipcbuf.remove.req_path, path);
  801ed7:	89 5c 24 04          	mov    %ebx,0x4(%esp)
  801edb:	c7 04 24 00 40 80 00 	movl   $0x804000,(%esp)
  801ee2:	e8 03 eb ff ff       	call   8009ea <strcpy>
	return fsipc(FSREQ_REMOVE, NULL);
  801ee7:	ba 00 00 00 00       	mov    $0x0,%edx
  801eec:	b8 07 00 00 00       	mov    $0x7,%eax
  801ef1:	e8 f2 fd ff ff       	call   801ce8 <fsipc>
}
  801ef6:	83 c4 14             	add    $0x14,%esp
  801ef9:	5b                   	pop    %ebx
  801efa:	5d                   	pop    %ebp
  801efb:	c3                   	ret    

00801efc <open>:
// 	The file descriptor index on success
// 	-E_BAD_PATH if the path is too long (>= MAXPATHLEN)
// 	< 0 for other errors.
int
open(const char *path, int mode)
{
  801efc:	55                   	push   %ebp
  801efd:	89 e5                	mov    %esp,%ebp
  801eff:	83 ec 28             	sub    $0x28,%esp
  801f02:	89 5d f8             	mov    %ebx,-0x8(%ebp)
  801f05:	89 75 fc             	mov    %esi,-0x4(%ebp)
  801f08:	8b 75 08             	mov    0x8(%ebp),%esi
	// Return the file descriptor index.
	// If any step after fd_alloc fails, use fd_close to free the
  struct Fd *f    = NULL;
  int r   = 0;

  if (!path)
  801f0b:	bb fd ff ff ff       	mov    $0xfffffffd,%ebx
  801f10:	85 f6                	test   %esi,%esi
  801f12:	74 65                	je     801f79 <open+0x7d>
	// (fd_alloc does not allocate a page, it just returns an
	// unused fd address.  Do you need to allocate a page?)
	//
	// Return the file descriptor index.
	// If any step after fd_alloc fails, use fd_close to free the
  struct Fd *f    = NULL;
  801f14:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)
  int r   = 0;

  if (!path)
    return -E_INVAL;
  if((r=fd_alloc(&f))<0)
  801f1b:	8d 45 f4             	lea    -0xc(%ebp),%eax
  801f1e:	89 04 24             	mov    %eax,(%esp)
  801f21:	e8 75 f7 ff ff       	call   80169b <fd_alloc>
  801f26:	89 c3                	mov    %eax,%ebx
  801f28:	85 c0                	test   %eax,%eax
  801f2a:	78 4d                	js     801f79 <open+0x7d>
    return r;

	strcpy(fsipcbuf.open.req_path, path);
  801f2c:	89 74 24 04          	mov    %esi,0x4(%esp)
  801f30:	c7 04 24 00 40 80 00 	movl   $0x804000,(%esp)
  801f37:	e8 ae ea ff ff       	call   8009ea <strcpy>
	fsipcbuf.open.req_omode = mode;
  801f3c:	8b 45 0c             	mov    0xc(%ebp),%eax
  801f3f:	a3 00 44 80 00       	mov    %eax,0x804400

  if ((r=fsipc(FSREQ_OPEN, f))<0) {
  801f44:	8b 55 f4             	mov    -0xc(%ebp),%edx
  801f47:	b8 01 00 00 00       	mov    $0x1,%eax
  801f4c:	e8 97 fd ff ff       	call   801ce8 <fsipc>
  801f51:	89 c3                	mov    %eax,%ebx
  801f53:	85 c0                	test   %eax,%eax
  801f55:	79 15                	jns    801f6c <open+0x70>
    fd_close(f, 0);
  801f57:	c7 44 24 04 00 00 00 	movl   $0x0,0x4(%esp)
  801f5e:	00 
  801f5f:	8b 45 f4             	mov    -0xc(%ebp),%eax
  801f62:	89 04 24             	mov    %eax,(%esp)
  801f65:	e8 3a fb ff ff       	call   801aa4 <fd_close>
    return r;
  801f6a:	eb 0d                	jmp    801f79 <open+0x7d>
  }
  return fd2num(f);
  801f6c:	8b 45 f4             	mov    -0xc(%ebp),%eax
  801f6f:	89 04 24             	mov    %eax,(%esp)
  801f72:	e8 f9 f6 ff ff       	call   801670 <fd2num>
  801f77:	89 c3                	mov    %eax,%ebx
}
  801f79:	89 d8                	mov    %ebx,%eax
  801f7b:	8b 5d f8             	mov    -0x8(%ebp),%ebx
  801f7e:	8b 75 fc             	mov    -0x4(%ebp),%esi
  801f81:	89 ec                	mov    %ebp,%esp
  801f83:	5d                   	pop    %ebp
  801f84:	c3                   	ret    
	...

00801f90 <devsock_stat>:
	return nsipc_send(fd->fd_sock.sockid, buf, n, 0);
}

static int
devsock_stat(struct Fd *fd, struct Stat *stat)
{
  801f90:	55                   	push   %ebp
  801f91:	89 e5                	mov    %esp,%ebp
  801f93:	83 ec 18             	sub    $0x18,%esp
	strcpy(stat->st_name, "<sock>");
  801f96:	c7 44 24 04 c8 34 80 	movl   $0x8034c8,0x4(%esp)
  801f9d:	00 
  801f9e:	8b 45 0c             	mov    0xc(%ebp),%eax
  801fa1:	89 04 24             	mov    %eax,(%esp)
  801fa4:	e8 41 ea ff ff       	call   8009ea <strcpy>
	return 0;
}
  801fa9:	b8 00 00 00 00       	mov    $0x0,%eax
  801fae:	c9                   	leave  
  801faf:	c3                   	ret    

00801fb0 <devsock_close>:
	return nsipc_shutdown(r, how);
}

static int
devsock_close(struct Fd *fd)
{
  801fb0:	55                   	push   %ebp
  801fb1:	89 e5                	mov    %esp,%ebp
  801fb3:	83 ec 18             	sub    $0x18,%esp
	return nsipc_close(fd->fd_sock.sockid);
  801fb6:	8b 45 08             	mov    0x8(%ebp),%eax
  801fb9:	8b 40 0c             	mov    0xc(%eax),%eax
  801fbc:	89 04 24             	mov    %eax,(%esp)
  801fbf:	e8 9d 02 00 00       	call   802261 <nsipc_close>
}
  801fc4:	c9                   	leave  
  801fc5:	c3                   	ret    

00801fc6 <devsock_write>:
	return nsipc_recv(fd->fd_sock.sockid, buf, n, 0);
}

static ssize_t
devsock_write(struct Fd *fd, const void *buf, size_t n)
{
  801fc6:	55                   	push   %ebp
  801fc7:	89 e5                	mov    %esp,%ebp
  801fc9:	83 ec 18             	sub    $0x18,%esp
	return nsipc_send(fd->fd_sock.sockid, buf, n, 0);
  801fcc:	c7 44 24 0c 00 00 00 	movl   $0x0,0xc(%esp)
  801fd3:	00 
  801fd4:	8b 45 10             	mov    0x10(%ebp),%eax
  801fd7:	89 44 24 08          	mov    %eax,0x8(%esp)
  801fdb:	8b 45 0c             	mov    0xc(%ebp),%eax
  801fde:	89 44 24 04          	mov    %eax,0x4(%esp)
  801fe2:	8b 45 08             	mov    0x8(%ebp),%eax
  801fe5:	8b 40 0c             	mov    0xc(%eax),%eax
  801fe8:	89 04 24             	mov    %eax,(%esp)
  801feb:	e8 ad 02 00 00       	call   80229d <nsipc_send>
}
  801ff0:	c9                   	leave  
  801ff1:	c3                   	ret    

00801ff2 <devsock_read>:
	return nsipc_listen(r, backlog);
}

static ssize_t
devsock_read(struct Fd *fd, void *buf, size_t n)
{
  801ff2:	55                   	push   %ebp
  801ff3:	89 e5                	mov    %esp,%ebp
  801ff5:	83 ec 18             	sub    $0x18,%esp
	return nsipc_recv(fd->fd_sock.sockid, buf, n, 0);
  801ff8:	c7 44 24 0c 00 00 00 	movl   $0x0,0xc(%esp)
  801fff:	00 
  802000:	8b 45 10             	mov    0x10(%ebp),%eax
  802003:	89 44 24 08          	mov    %eax,0x8(%esp)
  802007:	8b 45 0c             	mov    0xc(%ebp),%eax
  80200a:	89 44 24 04          	mov    %eax,0x4(%esp)
  80200e:	8b 45 08             	mov    0x8(%ebp),%eax
  802011:	8b 40 0c             	mov    0xc(%eax),%eax
  802014:	89 04 24             	mov    %eax,(%esp)
  802017:	e8 f4 02 00 00       	call   802310 <nsipc_recv>
}
  80201c:	c9                   	leave  
  80201d:	c3                   	ret    

0080201e <alloc_sockfd>:
	return sfd->fd_sock.sockid;
}

static int
alloc_sockfd(int sockid)
{
  80201e:	55                   	push   %ebp
  80201f:	89 e5                	mov    %esp,%ebp
  802021:	56                   	push   %esi
  802022:	53                   	push   %ebx
  802023:	83 ec 20             	sub    $0x20,%esp
  802026:	89 c6                	mov    %eax,%esi
	struct Fd *sfd;
	int r;

	if ((r = fd_alloc(&sfd)) < 0
  802028:	8d 45 f4             	lea    -0xc(%ebp),%eax
  80202b:	89 04 24             	mov    %eax,(%esp)
  80202e:	e8 68 f6 ff ff       	call   80169b <fd_alloc>
  802033:	89 c3                	mov    %eax,%ebx
  802035:	85 c0                	test   %eax,%eax
  802037:	78 21                	js     80205a <alloc_sockfd+0x3c>
	    || (r = sys_page_alloc(0, sfd, PTE_P|PTE_W|PTE_U)) < 0) {
  802039:	c7 44 24 08 07 00 00 	movl   $0x7,0x8(%esp)
  802040:	00 
  802041:	8b 45 f4             	mov    -0xc(%ebp),%eax
  802044:	89 44 24 04          	mov    %eax,0x4(%esp)
  802048:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  80204f:	e8 f2 f0 ff ff       	call   801146 <sys_page_alloc>
  802054:	89 c3                	mov    %eax,%ebx
alloc_sockfd(int sockid)
{
	struct Fd *sfd;
	int r;

	if ((r = fd_alloc(&sfd)) < 0
  802056:	85 c0                	test   %eax,%eax
  802058:	79 0a                	jns    802064 <alloc_sockfd+0x46>
	    || (r = sys_page_alloc(0, sfd, PTE_P|PTE_W|PTE_U)) < 0) {
		nsipc_close(sockid);
  80205a:	89 34 24             	mov    %esi,(%esp)
  80205d:	e8 ff 01 00 00       	call   802261 <nsipc_close>
		return r;
  802062:	eb 28                	jmp    80208c <alloc_sockfd+0x6e>
	}

	sfd->fd_dev_id = devsock.dev_id;
  802064:	8b 15 20 70 80 00    	mov    0x807020,%edx
  80206a:	8b 45 f4             	mov    -0xc(%ebp),%eax
  80206d:	89 10                	mov    %edx,(%eax)
	sfd->fd_omode = O_RDWR;
  80206f:	8b 45 f4             	mov    -0xc(%ebp),%eax
  802072:	c7 40 08 02 00 00 00 	movl   $0x2,0x8(%eax)
	sfd->fd_sock.sockid = sockid;
  802079:	8b 45 f4             	mov    -0xc(%ebp),%eax
  80207c:	89 70 0c             	mov    %esi,0xc(%eax)
	return fd2num(sfd);
  80207f:	8b 45 f4             	mov    -0xc(%ebp),%eax
  802082:	89 04 24             	mov    %eax,(%esp)
  802085:	e8 e6 f5 ff ff       	call   801670 <fd2num>
  80208a:	89 c3                	mov    %eax,%ebx
}
  80208c:	89 d8                	mov    %ebx,%eax
  80208e:	83 c4 20             	add    $0x20,%esp
  802091:	5b                   	pop    %ebx
  802092:	5e                   	pop    %esi
  802093:	5d                   	pop    %ebp
  802094:	c3                   	ret    

00802095 <socket>:
	return 0;
}

int
socket(int domain, int type, int protocol)
{
  802095:	55                   	push   %ebp
  802096:	89 e5                	mov    %esp,%ebp
  802098:	83 ec 18             	sub    $0x18,%esp
	int r;
	if ((r = nsipc_socket(domain, type, protocol)) < 0)
  80209b:	8b 45 10             	mov    0x10(%ebp),%eax
  80209e:	89 44 24 08          	mov    %eax,0x8(%esp)
  8020a2:	8b 45 0c             	mov    0xc(%ebp),%eax
  8020a5:	89 44 24 04          	mov    %eax,0x4(%esp)
  8020a9:	8b 45 08             	mov    0x8(%ebp),%eax
  8020ac:	89 04 24             	mov    %eax,(%esp)
  8020af:	e8 61 01 00 00       	call   802215 <nsipc_socket>
  8020b4:	85 c0                	test   %eax,%eax
  8020b6:	78 05                	js     8020bd <socket+0x28>
		return r;
	return alloc_sockfd(r);
  8020b8:	e8 61 ff ff ff       	call   80201e <alloc_sockfd>
}
  8020bd:	c9                   	leave  
  8020be:	66 90                	xchg   %ax,%ax
  8020c0:	c3                   	ret    

008020c1 <fd2sockid>:
	.dev_stat =	devsock_stat,
};

static int
fd2sockid(int fd)
{
  8020c1:	55                   	push   %ebp
  8020c2:	89 e5                	mov    %esp,%ebp
  8020c4:	83 ec 28             	sub    $0x28,%esp
	struct Fd *sfd;
	int r;

	if ((r = fd_lookup(fd, &sfd)) < 0)
  8020c7:	8d 55 f4             	lea    -0xc(%ebp),%edx
  8020ca:	89 54 24 04          	mov    %edx,0x4(%esp)
  8020ce:	89 04 24             	mov    %eax,(%esp)
  8020d1:	e8 37 f6 ff ff       	call   80170d <fd_lookup>
  8020d6:	85 c0                	test   %eax,%eax
  8020d8:	78 15                	js     8020ef <fd2sockid+0x2e>
		return r;
	if (sfd->fd_dev_id != devsock.dev_id)
  8020da:	8b 55 f4             	mov    -0xc(%ebp),%edx
  8020dd:	8b 0a                	mov    (%edx),%ecx
  8020df:	b8 f1 ff ff ff       	mov    $0xfffffff1,%eax
  8020e4:	3b 0d 20 70 80 00    	cmp    0x807020,%ecx
  8020ea:	75 03                	jne    8020ef <fd2sockid+0x2e>
		return -E_NOT_SUPP;
	return sfd->fd_sock.sockid;
  8020ec:	8b 42 0c             	mov    0xc(%edx),%eax
}
  8020ef:	c9                   	leave  
  8020f0:	c3                   	ret    

008020f1 <listen>:
	return nsipc_connect(r, name, namelen);
}

int
listen(int s, int backlog)
{
  8020f1:	55                   	push   %ebp
  8020f2:	89 e5                	mov    %esp,%ebp
  8020f4:	83 ec 18             	sub    $0x18,%esp
	int r;
	if ((r = fd2sockid(s)) < 0)
  8020f7:	8b 45 08             	mov    0x8(%ebp),%eax
  8020fa:	e8 c2 ff ff ff       	call   8020c1 <fd2sockid>
  8020ff:	85 c0                	test   %eax,%eax
  802101:	78 0f                	js     802112 <listen+0x21>
		return r;
	return nsipc_listen(r, backlog);
  802103:	8b 55 0c             	mov    0xc(%ebp),%edx
  802106:	89 54 24 04          	mov    %edx,0x4(%esp)
  80210a:	89 04 24             	mov    %eax,(%esp)
  80210d:	e8 2d 01 00 00       	call   80223f <nsipc_listen>
}
  802112:	c9                   	leave  
  802113:	c3                   	ret    

00802114 <connect>:
	return nsipc_close(fd->fd_sock.sockid);
}

int
connect(int s, const struct sockaddr *name, socklen_t namelen)
{
  802114:	55                   	push   %ebp
  802115:	89 e5                	mov    %esp,%ebp
  802117:	83 ec 18             	sub    $0x18,%esp
	int r;
	if ((r = fd2sockid(s)) < 0)
  80211a:	8b 45 08             	mov    0x8(%ebp),%eax
  80211d:	e8 9f ff ff ff       	call   8020c1 <fd2sockid>
  802122:	85 c0                	test   %eax,%eax
  802124:	78 16                	js     80213c <connect+0x28>
		return r;
	return nsipc_connect(r, name, namelen);
  802126:	8b 55 10             	mov    0x10(%ebp),%edx
  802129:	89 54 24 08          	mov    %edx,0x8(%esp)
  80212d:	8b 55 0c             	mov    0xc(%ebp),%edx
  802130:	89 54 24 04          	mov    %edx,0x4(%esp)
  802134:	89 04 24             	mov    %eax,(%esp)
  802137:	e8 54 02 00 00       	call   802390 <nsipc_connect>
}
  80213c:	c9                   	leave  
  80213d:	c3                   	ret    

0080213e <shutdown>:
	return nsipc_bind(r, name, namelen);
}

int
shutdown(int s, int how)
{
  80213e:	55                   	push   %ebp
  80213f:	89 e5                	mov    %esp,%ebp
  802141:	83 ec 18             	sub    $0x18,%esp
	int r;
	if ((r = fd2sockid(s)) < 0)
  802144:	8b 45 08             	mov    0x8(%ebp),%eax
  802147:	e8 75 ff ff ff       	call   8020c1 <fd2sockid>
  80214c:	85 c0                	test   %eax,%eax
  80214e:	78 0f                	js     80215f <shutdown+0x21>
		return r;
	return nsipc_shutdown(r, how);
  802150:	8b 55 0c             	mov    0xc(%ebp),%edx
  802153:	89 54 24 04          	mov    %edx,0x4(%esp)
  802157:	89 04 24             	mov    %eax,(%esp)
  80215a:	e8 1c 01 00 00       	call   80227b <nsipc_shutdown>
}
  80215f:	c9                   	leave  
  802160:	c3                   	ret    

00802161 <bind>:
	return alloc_sockfd(r);
}

int
bind(int s, struct sockaddr *name, socklen_t namelen)
{
  802161:	55                   	push   %ebp
  802162:	89 e5                	mov    %esp,%ebp
  802164:	83 ec 18             	sub    $0x18,%esp
	int r;
	if ((r = fd2sockid(s)) < 0)
  802167:	8b 45 08             	mov    0x8(%ebp),%eax
  80216a:	e8 52 ff ff ff       	call   8020c1 <fd2sockid>
  80216f:	85 c0                	test   %eax,%eax
  802171:	78 16                	js     802189 <bind+0x28>
		return r;
	return nsipc_bind(r, name, namelen);
  802173:	8b 55 10             	mov    0x10(%ebp),%edx
  802176:	89 54 24 08          	mov    %edx,0x8(%esp)
  80217a:	8b 55 0c             	mov    0xc(%ebp),%edx
  80217d:	89 54 24 04          	mov    %edx,0x4(%esp)
  802181:	89 04 24             	mov    %eax,(%esp)
  802184:	e8 46 02 00 00       	call   8023cf <nsipc_bind>
}
  802189:	c9                   	leave  
  80218a:	c3                   	ret    

0080218b <accept>:
	return fd2num(sfd);
}

int
accept(int s, struct sockaddr *addr, socklen_t *addrlen)
{
  80218b:	55                   	push   %ebp
  80218c:	89 e5                	mov    %esp,%ebp
  80218e:	83 ec 18             	sub    $0x18,%esp
	int r;
	if ((r = fd2sockid(s)) < 0)
  802191:	8b 45 08             	mov    0x8(%ebp),%eax
  802194:	e8 28 ff ff ff       	call   8020c1 <fd2sockid>
  802199:	85 c0                	test   %eax,%eax
  80219b:	78 1f                	js     8021bc <accept+0x31>
		return r;
	if ((r = nsipc_accept(r, addr, addrlen)) < 0)
  80219d:	8b 55 10             	mov    0x10(%ebp),%edx
  8021a0:	89 54 24 08          	mov    %edx,0x8(%esp)
  8021a4:	8b 55 0c             	mov    0xc(%ebp),%edx
  8021a7:	89 54 24 04          	mov    %edx,0x4(%esp)
  8021ab:	89 04 24             	mov    %eax,(%esp)
  8021ae:	e8 5b 02 00 00       	call   80240e <nsipc_accept>
  8021b3:	85 c0                	test   %eax,%eax
  8021b5:	78 05                	js     8021bc <accept+0x31>
		return r;
	return alloc_sockfd(r);
  8021b7:	e8 62 fe ff ff       	call   80201e <alloc_sockfd>
}
  8021bc:	c9                   	leave  
  8021bd:	8d 76 00             	lea    0x0(%esi),%esi
  8021c0:	c3                   	ret    
	...

008021d0 <nsipc>:
// may be written back to nsipcbuf.
// type: request code, passed as the simple integer IPC value.
// Returns 0 if successful, < 0 on failure.
static int
nsipc(unsigned type)
{
  8021d0:	55                   	push   %ebp
  8021d1:	89 e5                	mov    %esp,%ebp
  8021d3:	83 ec 28             	sub    $0x28,%esp
    int r=0;
    envid_t from;
	if (debug)
		cprintf("[%08x] nsipc %d\n", env->env_id, type);

	ipc_send(envs[2].env_id, type, &nsipcbuf, PTE_P|PTE_W|PTE_U);
  8021d6:	8b 15 44 01 c0 ee    	mov    0xeec00144,%edx
  8021dc:	c7 44 24 0c 07 00 00 	movl   $0x7,0xc(%esp)
  8021e3:	00 
  8021e4:	c7 44 24 08 00 60 80 	movl   $0x806000,0x8(%esp)
  8021eb:	00 
  8021ec:	89 44 24 04          	mov    %eax,0x4(%esp)
  8021f0:	89 14 24             	mov    %edx,(%esp)
  8021f3:	e8 a8 08 00 00       	call   802aa0 <ipc_send>
	r=ipc_recv(&from, NULL, NULL);
  8021f8:	c7 44 24 08 00 00 00 	movl   $0x0,0x8(%esp)
  8021ff:	00 
  802200:	c7 44 24 04 00 00 00 	movl   $0x0,0x4(%esp)
  802207:	00 
  802208:	8d 45 f4             	lea    -0xc(%ebp),%eax
  80220b:	89 04 24             	mov    %eax,(%esp)
  80220e:	e8 ff 08 00 00       	call   802b12 <ipc_recv>
    return r;
}
  802213:	c9                   	leave  
  802214:	c3                   	ret    

00802215 <nsipc_socket>:
	return nsipc(NSREQ_SEND);
}

int
nsipc_socket(int domain, int type, int protocol)
{
  802215:	55                   	push   %ebp
  802216:	89 e5                	mov    %esp,%ebp
  802218:	83 ec 08             	sub    $0x8,%esp
	nsipcbuf.socket.req_domain = domain;
  80221b:	8b 45 08             	mov    0x8(%ebp),%eax
  80221e:	a3 00 60 80 00       	mov    %eax,0x806000
	nsipcbuf.socket.req_type = type;
  802223:	8b 45 0c             	mov    0xc(%ebp),%eax
  802226:	a3 04 60 80 00       	mov    %eax,0x806004
	nsipcbuf.socket.req_protocol = protocol;
  80222b:	8b 45 10             	mov    0x10(%ebp),%eax
  80222e:	a3 08 60 80 00       	mov    %eax,0x806008
	return nsipc(NSREQ_SOCKET);
  802233:	b8 09 00 00 00       	mov    $0x9,%eax
  802238:	e8 93 ff ff ff       	call   8021d0 <nsipc>
}
  80223d:	c9                   	leave  
  80223e:	c3                   	ret    

0080223f <nsipc_listen>:
	return nsipc(NSREQ_CONNECT);
}

int
nsipc_listen(int s, int backlog)
{
  80223f:	55                   	push   %ebp
  802240:	89 e5                	mov    %esp,%ebp
  802242:	83 ec 08             	sub    $0x8,%esp
	nsipcbuf.listen.req_s = s;
  802245:	8b 45 08             	mov    0x8(%ebp),%eax
  802248:	a3 00 60 80 00       	mov    %eax,0x806000
	nsipcbuf.listen.req_backlog = backlog;
  80224d:	8b 45 0c             	mov    0xc(%ebp),%eax
  802250:	a3 04 60 80 00       	mov    %eax,0x806004
	return nsipc(NSREQ_LISTEN);
  802255:	b8 06 00 00 00       	mov    $0x6,%eax
  80225a:	e8 71 ff ff ff       	call   8021d0 <nsipc>
}
  80225f:	c9                   	leave  
  802260:	c3                   	ret    

00802261 <nsipc_close>:
	return nsipc(NSREQ_SHUTDOWN);
}

int
nsipc_close(int s)
{
  802261:	55                   	push   %ebp
  802262:	89 e5                	mov    %esp,%ebp
  802264:	83 ec 08             	sub    $0x8,%esp
	nsipcbuf.close.req_s = s;
  802267:	8b 45 08             	mov    0x8(%ebp),%eax
  80226a:	a3 00 60 80 00       	mov    %eax,0x806000
	return nsipc(NSREQ_CLOSE);
  80226f:	b8 04 00 00 00       	mov    $0x4,%eax
  802274:	e8 57 ff ff ff       	call   8021d0 <nsipc>
}
  802279:	c9                   	leave  
  80227a:	c3                   	ret    

0080227b <nsipc_shutdown>:
	return nsipc(NSREQ_BIND);
}

int
nsipc_shutdown(int s, int how)
{
  80227b:	55                   	push   %ebp
  80227c:	89 e5                	mov    %esp,%ebp
  80227e:	83 ec 08             	sub    $0x8,%esp
	nsipcbuf.shutdown.req_s = s;
  802281:	8b 45 08             	mov    0x8(%ebp),%eax
  802284:	a3 00 60 80 00       	mov    %eax,0x806000
	nsipcbuf.shutdown.req_how = how;
  802289:	8b 45 0c             	mov    0xc(%ebp),%eax
  80228c:	a3 04 60 80 00       	mov    %eax,0x806004
	return nsipc(NSREQ_SHUTDOWN);
  802291:	b8 03 00 00 00       	mov    $0x3,%eax
  802296:	e8 35 ff ff ff       	call   8021d0 <nsipc>
}
  80229b:	c9                   	leave  
  80229c:	c3                   	ret    

0080229d <nsipc_send>:
	return r;
}

int
nsipc_send(int s, const void *buf, int size, unsigned int flags)
{
  80229d:	55                   	push   %ebp
  80229e:	89 e5                	mov    %esp,%ebp
  8022a0:	53                   	push   %ebx
  8022a1:	83 ec 14             	sub    $0x14,%esp
  8022a4:	8b 5d 10             	mov    0x10(%ebp),%ebx
	nsipcbuf.send.req_s = s;
  8022a7:	8b 45 08             	mov    0x8(%ebp),%eax
  8022aa:	a3 00 60 80 00       	mov    %eax,0x806000
	assert(size < 1600);
  8022af:	81 fb 3f 06 00 00    	cmp    $0x63f,%ebx
  8022b5:	7e 24                	jle    8022db <nsipc_send+0x3e>
  8022b7:	c7 44 24 0c d4 34 80 	movl   $0x8034d4,0xc(%esp)
  8022be:	00 
  8022bf:	c7 44 24 08 e0 34 80 	movl   $0x8034e0,0x8(%esp)
  8022c6:	00 
  8022c7:	c7 44 24 04 69 00 00 	movl   $0x69,0x4(%esp)
  8022ce:	00 
  8022cf:	c7 04 24 f5 34 80 00 	movl   $0x8034f5,(%esp)
  8022d6:	e8 7d df ff ff       	call   800258 <_panic>
	memmove(&nsipcbuf.send.req_buf, buf, size);
  8022db:	89 5c 24 08          	mov    %ebx,0x8(%esp)
  8022df:	8b 45 0c             	mov    0xc(%ebp),%eax
  8022e2:	89 44 24 04          	mov    %eax,0x4(%esp)
  8022e6:	c7 04 24 0c 60 80 00 	movl   $0x80600c,(%esp)
  8022ed:	e8 b3 e8 ff ff       	call   800ba5 <memmove>
	nsipcbuf.send.req_size = size;
  8022f2:	89 1d 04 60 80 00    	mov    %ebx,0x806004
	nsipcbuf.send.req_flags = flags;
  8022f8:	8b 45 14             	mov    0x14(%ebp),%eax
  8022fb:	a3 08 60 80 00       	mov    %eax,0x806008
	return nsipc(NSREQ_SEND);
  802300:	b8 08 00 00 00       	mov    $0x8,%eax
  802305:	e8 c6 fe ff ff       	call   8021d0 <nsipc>
}
  80230a:	83 c4 14             	add    $0x14,%esp
  80230d:	5b                   	pop    %ebx
  80230e:	5d                   	pop    %ebp
  80230f:	c3                   	ret    

00802310 <nsipc_recv>:
	return nsipc(NSREQ_LISTEN);
}

int
nsipc_recv(int s, void *mem, int len, unsigned int flags)
{
  802310:	55                   	push   %ebp
  802311:	89 e5                	mov    %esp,%ebp
  802313:	56                   	push   %esi
  802314:	53                   	push   %ebx
  802315:	83 ec 10             	sub    $0x10,%esp
  802318:	8b 75 10             	mov    0x10(%ebp),%esi
	int r;

	nsipcbuf.recv.req_s = s;
  80231b:	8b 45 08             	mov    0x8(%ebp),%eax
  80231e:	a3 00 60 80 00       	mov    %eax,0x806000
	nsipcbuf.recv.req_len = len;
  802323:	89 35 04 60 80 00    	mov    %esi,0x806004
	nsipcbuf.recv.req_flags = flags;
  802329:	8b 45 14             	mov    0x14(%ebp),%eax
  80232c:	a3 08 60 80 00       	mov    %eax,0x806008

	if ((r = nsipc(NSREQ_RECV)) >= 0) {
  802331:	b8 07 00 00 00       	mov    $0x7,%eax
  802336:	e8 95 fe ff ff       	call   8021d0 <nsipc>
  80233b:	89 c3                	mov    %eax,%ebx
  80233d:	85 c0                	test   %eax,%eax
  80233f:	78 46                	js     802387 <nsipc_recv+0x77>
		assert(r < 1600 && r <= len);
  802341:	3d 3f 06 00 00       	cmp    $0x63f,%eax
  802346:	7f 04                	jg     80234c <nsipc_recv+0x3c>
  802348:	39 c6                	cmp    %eax,%esi
  80234a:	7d 24                	jge    802370 <nsipc_recv+0x60>
  80234c:	c7 44 24 0c 01 35 80 	movl   $0x803501,0xc(%esp)
  802353:	00 
  802354:	c7 44 24 08 e0 34 80 	movl   $0x8034e0,0x8(%esp)
  80235b:	00 
  80235c:	c7 44 24 04 5e 00 00 	movl   $0x5e,0x4(%esp)
  802363:	00 
  802364:	c7 04 24 f5 34 80 00 	movl   $0x8034f5,(%esp)
  80236b:	e8 e8 de ff ff       	call   800258 <_panic>
		memmove(mem, nsipcbuf.recvRet.ret_buf, r);
  802370:	89 44 24 08          	mov    %eax,0x8(%esp)
  802374:	c7 44 24 04 00 60 80 	movl   $0x806000,0x4(%esp)
  80237b:	00 
  80237c:	8b 45 0c             	mov    0xc(%ebp),%eax
  80237f:	89 04 24             	mov    %eax,(%esp)
  802382:	e8 1e e8 ff ff       	call   800ba5 <memmove>
	}

	return r;
}
  802387:	89 d8                	mov    %ebx,%eax
  802389:	83 c4 10             	add    $0x10,%esp
  80238c:	5b                   	pop    %ebx
  80238d:	5e                   	pop    %esi
  80238e:	5d                   	pop    %ebp
  80238f:	c3                   	ret    

00802390 <nsipc_connect>:
	return nsipc(NSREQ_CLOSE);
}

int
nsipc_connect(int s, const struct sockaddr *name, socklen_t namelen)
{
  802390:	55                   	push   %ebp
  802391:	89 e5                	mov    %esp,%ebp
  802393:	53                   	push   %ebx
  802394:	83 ec 14             	sub    $0x14,%esp
  802397:	8b 5d 10             	mov    0x10(%ebp),%ebx
	nsipcbuf.connect.req_s = s;
  80239a:	8b 45 08             	mov    0x8(%ebp),%eax
  80239d:	a3 00 60 80 00       	mov    %eax,0x806000
	memmove(&nsipcbuf.connect.req_name, name, namelen);
  8023a2:	89 5c 24 08          	mov    %ebx,0x8(%esp)
  8023a6:	8b 45 0c             	mov    0xc(%ebp),%eax
  8023a9:	89 44 24 04          	mov    %eax,0x4(%esp)
  8023ad:	c7 04 24 04 60 80 00 	movl   $0x806004,(%esp)
  8023b4:	e8 ec e7 ff ff       	call   800ba5 <memmove>
	nsipcbuf.connect.req_namelen = namelen;
  8023b9:	89 1d 14 60 80 00    	mov    %ebx,0x806014
	return nsipc(NSREQ_CONNECT);
  8023bf:	b8 05 00 00 00       	mov    $0x5,%eax
  8023c4:	e8 07 fe ff ff       	call   8021d0 <nsipc>
}
  8023c9:	83 c4 14             	add    $0x14,%esp
  8023cc:	5b                   	pop    %ebx
  8023cd:	5d                   	pop    %ebp
  8023ce:	c3                   	ret    

008023cf <nsipc_bind>:
	return r;
}

int
nsipc_bind(int s, struct sockaddr *name, socklen_t namelen)
{
  8023cf:	55                   	push   %ebp
  8023d0:	89 e5                	mov    %esp,%ebp
  8023d2:	53                   	push   %ebx
  8023d3:	83 ec 14             	sub    $0x14,%esp
  8023d6:	8b 5d 10             	mov    0x10(%ebp),%ebx
	nsipcbuf.bind.req_s = s;
  8023d9:	8b 45 08             	mov    0x8(%ebp),%eax
  8023dc:	a3 00 60 80 00       	mov    %eax,0x806000
	memmove(&nsipcbuf.bind.req_name, name, namelen);
  8023e1:	89 5c 24 08          	mov    %ebx,0x8(%esp)
  8023e5:	8b 45 0c             	mov    0xc(%ebp),%eax
  8023e8:	89 44 24 04          	mov    %eax,0x4(%esp)
  8023ec:	c7 04 24 04 60 80 00 	movl   $0x806004,(%esp)
  8023f3:	e8 ad e7 ff ff       	call   800ba5 <memmove>
	nsipcbuf.bind.req_namelen = namelen;
  8023f8:	89 1d 14 60 80 00    	mov    %ebx,0x806014
	return nsipc(NSREQ_BIND);
  8023fe:	b8 02 00 00 00       	mov    $0x2,%eax
  802403:	e8 c8 fd ff ff       	call   8021d0 <nsipc>
}
  802408:	83 c4 14             	add    $0x14,%esp
  80240b:	5b                   	pop    %ebx
  80240c:	5d                   	pop    %ebp
  80240d:	c3                   	ret    

0080240e <nsipc_accept>:
    return r;
}

int
nsipc_accept(int s, struct sockaddr *addr, socklen_t *addrlen)
{
  80240e:	55                   	push   %ebp
  80240f:	89 e5                	mov    %esp,%ebp
  802411:	83 ec 18             	sub    $0x18,%esp
  802414:	89 5d f8             	mov    %ebx,-0x8(%ebp)
  802417:	89 75 fc             	mov    %esi,-0x4(%ebp)
	int r;
	
	nsipcbuf.accept.req_s = s;
  80241a:	8b 45 08             	mov    0x8(%ebp),%eax
  80241d:	a3 00 60 80 00       	mov    %eax,0x806000
	if ((r = nsipc(NSREQ_ACCEPT)) >= 0) {
  802422:	b8 01 00 00 00       	mov    $0x1,%eax
  802427:	e8 a4 fd ff ff       	call   8021d0 <nsipc>
  80242c:	89 c3                	mov    %eax,%ebx
  80242e:	85 c0                	test   %eax,%eax
  802430:	78 25                	js     802457 <nsipc_accept+0x49>
		struct Nsret_accept *ret = &nsipcbuf.acceptRet;
		memmove(addr, &ret->ret_addr, ret->ret_addrlen);
  802432:	be 10 60 80 00       	mov    $0x806010,%esi
  802437:	8b 06                	mov    (%esi),%eax
  802439:	89 44 24 08          	mov    %eax,0x8(%esp)
  80243d:	c7 44 24 04 00 60 80 	movl   $0x806000,0x4(%esp)
  802444:	00 
  802445:	8b 45 0c             	mov    0xc(%ebp),%eax
  802448:	89 04 24             	mov    %eax,(%esp)
  80244b:	e8 55 e7 ff ff       	call   800ba5 <memmove>
		*addrlen = ret->ret_addrlen;
  802450:	8b 16                	mov    (%esi),%edx
  802452:	8b 45 10             	mov    0x10(%ebp),%eax
  802455:	89 10                	mov    %edx,(%eax)
	}
	return r;
}
  802457:	89 d8                	mov    %ebx,%eax
  802459:	8b 5d f8             	mov    -0x8(%ebp),%ebx
  80245c:	8b 75 fc             	mov    -0x4(%ebp),%esi
  80245f:	89 ec                	mov    %ebp,%esp
  802461:	5d                   	pop    %ebp
  802462:	c3                   	ret    
	...

00802470 <devpipe_stat>:
	return i;
}

static int
devpipe_stat(struct Fd *fd, struct Stat *stat)
{
  802470:	55                   	push   %ebp
  802471:	89 e5                	mov    %esp,%ebp
  802473:	83 ec 18             	sub    $0x18,%esp
  802476:	89 5d f8             	mov    %ebx,-0x8(%ebp)
  802479:	89 75 fc             	mov    %esi,-0x4(%ebp)
  80247c:	8b 75 0c             	mov    0xc(%ebp),%esi
	struct Pipe *p = (struct Pipe*) fd2data(fd);
  80247f:	8b 45 08             	mov    0x8(%ebp),%eax
  802482:	89 04 24             	mov    %eax,(%esp)
  802485:	e8 f6 f1 ff ff       	call   801680 <fd2data>
  80248a:	89 c3                	mov    %eax,%ebx
	strcpy(stat->st_name, "<pipe>");
  80248c:	c7 44 24 04 16 35 80 	movl   $0x803516,0x4(%esp)
  802493:	00 
  802494:	89 34 24             	mov    %esi,(%esp)
  802497:	e8 4e e5 ff ff       	call   8009ea <strcpy>
	stat->st_size = p->p_wpos - p->p_rpos;
  80249c:	8b 43 04             	mov    0x4(%ebx),%eax
  80249f:	2b 03                	sub    (%ebx),%eax
  8024a1:	89 86 80 00 00 00    	mov    %eax,0x80(%esi)
	stat->st_isdir = 0;
  8024a7:	c7 86 84 00 00 00 00 	movl   $0x0,0x84(%esi)
  8024ae:	00 00 00 
	stat->st_dev = &devpipe;
  8024b1:	c7 86 88 00 00 00 3c 	movl   $0x80703c,0x88(%esi)
  8024b8:	70 80 00 
	return 0;
}
  8024bb:	b8 00 00 00 00       	mov    $0x0,%eax
  8024c0:	8b 5d f8             	mov    -0x8(%ebp),%ebx
  8024c3:	8b 75 fc             	mov    -0x4(%ebp),%esi
  8024c6:	89 ec                	mov    %ebp,%esp
  8024c8:	5d                   	pop    %ebp
  8024c9:	c3                   	ret    

008024ca <devpipe_close>:

static int
devpipe_close(struct Fd *fd)
{
  8024ca:	55                   	push   %ebp
  8024cb:	89 e5                	mov    %esp,%ebp
  8024cd:	53                   	push   %ebx
  8024ce:	83 ec 14             	sub    $0x14,%esp
  8024d1:	8b 5d 08             	mov    0x8(%ebp),%ebx
	(void) sys_page_unmap(0, fd);
  8024d4:	89 5c 24 04          	mov    %ebx,0x4(%esp)
  8024d8:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  8024df:	e8 a6 eb ff ff       	call   80108a <sys_page_unmap>
	return sys_page_unmap(0, fd2data(fd));
  8024e4:	89 1c 24             	mov    %ebx,(%esp)
  8024e7:	e8 94 f1 ff ff       	call   801680 <fd2data>
  8024ec:	89 44 24 04          	mov    %eax,0x4(%esp)
  8024f0:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  8024f7:	e8 8e eb ff ff       	call   80108a <sys_page_unmap>
}
  8024fc:	83 c4 14             	add    $0x14,%esp
  8024ff:	5b                   	pop    %ebx
  802500:	5d                   	pop    %ebp
  802501:	c3                   	ret    

00802502 <_pipeisclosed>:
	return r;
}

static int
_pipeisclosed(struct Fd *fd, struct Pipe *p)
{
  802502:	55                   	push   %ebp
  802503:	89 e5                	mov    %esp,%ebp
  802505:	57                   	push   %edi
  802506:	56                   	push   %esi
  802507:	53                   	push   %ebx
  802508:	83 ec 2c             	sub    $0x2c,%esp
  80250b:	89 c7                	mov    %eax,%edi
  80250d:	89 55 e4             	mov    %edx,-0x1c(%ebp)
	int n, nn, ret;

	while (1) {
		n = env->env_runs;
  802510:	a1 74 70 80 00       	mov    0x807074,%eax
  802515:	8b 58 58             	mov    0x58(%eax),%ebx
		ret = pageref(fd) == pageref(p);
  802518:	89 3c 24             	mov    %edi,(%esp)
  80251b:	e8 44 06 00 00       	call   802b64 <pageref>
  802520:	89 c6                	mov    %eax,%esi
  802522:	8b 45 e4             	mov    -0x1c(%ebp),%eax
  802525:	89 04 24             	mov    %eax,(%esp)
  802528:	e8 37 06 00 00       	call   802b64 <pageref>
  80252d:	39 c6                	cmp    %eax,%esi
  80252f:	0f 94 c0             	sete   %al
  802532:	0f b6 c0             	movzbl %al,%eax
		nn = env->env_runs;
  802535:	8b 15 74 70 80 00    	mov    0x807074,%edx
  80253b:	8b 4a 58             	mov    0x58(%edx),%ecx
		if (n == nn)
  80253e:	39 cb                	cmp    %ecx,%ebx
  802540:	75 08                	jne    80254a <_pipeisclosed+0x48>
			return ret;
		if (n != nn && ret == 1)
			cprintf("pipe race avoided\n", n, env->env_runs, ret);
	}
}
  802542:	83 c4 2c             	add    $0x2c,%esp
  802545:	5b                   	pop    %ebx
  802546:	5e                   	pop    %esi
  802547:	5f                   	pop    %edi
  802548:	5d                   	pop    %ebp
  802549:	c3                   	ret    
		n = env->env_runs;
		ret = pageref(fd) == pageref(p);
		nn = env->env_runs;
		if (n == nn)
			return ret;
		if (n != nn && ret == 1)
  80254a:	83 f8 01             	cmp    $0x1,%eax
  80254d:	75 c1                	jne    802510 <_pipeisclosed+0xe>
			cprintf("pipe race avoided\n", n, env->env_runs, ret);
  80254f:	8b 52 58             	mov    0x58(%edx),%edx
  802552:	89 44 24 0c          	mov    %eax,0xc(%esp)
  802556:	89 54 24 08          	mov    %edx,0x8(%esp)
  80255a:	89 5c 24 04          	mov    %ebx,0x4(%esp)
  80255e:	c7 04 24 1d 35 80 00 	movl   $0x80351d,(%esp)
  802565:	e8 b3 dd ff ff       	call   80031d <cprintf>
  80256a:	eb a4                	jmp    802510 <_pipeisclosed+0xe>

0080256c <devpipe_write>:
	return i;
}

static ssize_t
devpipe_write(struct Fd *fd, const void *vbuf, size_t n)
{
  80256c:	55                   	push   %ebp
  80256d:	89 e5                	mov    %esp,%ebp
  80256f:	57                   	push   %edi
  802570:	56                   	push   %esi
  802571:	53                   	push   %ebx
  802572:	83 ec 1c             	sub    $0x1c,%esp
  802575:	8b 75 08             	mov    0x8(%ebp),%esi
	const uint8_t *buf;
	size_t i;
	struct Pipe *p;

	p = (struct Pipe*) fd2data(fd);
  802578:	89 34 24             	mov    %esi,(%esp)
  80257b:	e8 00 f1 ff ff       	call   801680 <fd2data>
  802580:	89 c3                	mov    %eax,%ebx
	if (debug)
		cprintf("[%08x] devpipe_write %08x %d rpos %d wpos %d\n",
			env->env_id, vpt[VPN(p)], n, p->p_rpos, p->p_wpos);

	buf = vbuf;
	for (i = 0; i < n; i++) {
  802582:	bf 00 00 00 00       	mov    $0x0,%edi
  802587:	83 7d 10 00          	cmpl   $0x0,0x10(%ebp)
  80258b:	75 54                	jne    8025e1 <devpipe_write+0x75>
  80258d:	eb 60                	jmp    8025ef <devpipe_write+0x83>
		while (p->p_wpos >= p->p_rpos + sizeof(p->p_buf)) {
			// pipe is full
			// if all the readers are gone
			// (it's only writers like us now),
			// note eof
			if (_pipeisclosed(fd, p))
  80258f:	89 da                	mov    %ebx,%edx
  802591:	89 f0                	mov    %esi,%eax
  802593:	e8 6a ff ff ff       	call   802502 <_pipeisclosed>
  802598:	85 c0                	test   %eax,%eax
  80259a:	74 07                	je     8025a3 <devpipe_write+0x37>
  80259c:	b8 00 00 00 00       	mov    $0x0,%eax
  8025a1:	eb 53                	jmp    8025f6 <devpipe_write+0x8a>
				return 0;
			// yield and see what happens
			if (debug)
				cprintf("devpipe_write yield\n");
			sys_yield();
  8025a3:	90                   	nop
  8025a4:	8d 74 26 00          	lea    0x0(%esi,%eiz,1),%esi
  8025a8:	e8 f8 eb ff ff       	call   8011a5 <sys_yield>
		cprintf("[%08x] devpipe_write %08x %d rpos %d wpos %d\n",
			env->env_id, vpt[VPN(p)], n, p->p_rpos, p->p_wpos);

	buf = vbuf;
	for (i = 0; i < n; i++) {
		while (p->p_wpos >= p->p_rpos + sizeof(p->p_buf)) {
  8025ad:	8b 43 04             	mov    0x4(%ebx),%eax
  8025b0:	8b 13                	mov    (%ebx),%edx
  8025b2:	83 c2 20             	add    $0x20,%edx
  8025b5:	39 d0                	cmp    %edx,%eax
  8025b7:	73 d6                	jae    80258f <devpipe_write+0x23>
				cprintf("devpipe_write yield\n");
			sys_yield();
		}
		// there's room for a byte.  store it.
		// wait to increment wpos until the byte is stored!
		p->p_buf[p->p_wpos % PIPEBUFSIZ] = buf[i];
  8025b9:	89 c2                	mov    %eax,%edx
  8025bb:	c1 fa 1f             	sar    $0x1f,%edx
  8025be:	c1 ea 1b             	shr    $0x1b,%edx
  8025c1:	01 d0                	add    %edx,%eax
  8025c3:	83 e0 1f             	and    $0x1f,%eax
  8025c6:	29 d0                	sub    %edx,%eax
  8025c8:	89 c2                	mov    %eax,%edx
  8025ca:	8b 4d 0c             	mov    0xc(%ebp),%ecx
  8025cd:	0f b6 04 39          	movzbl (%ecx,%edi,1),%eax
  8025d1:	88 44 13 08          	mov    %al,0x8(%ebx,%edx,1)
		p->p_wpos++;
  8025d5:	83 43 04 01          	addl   $0x1,0x4(%ebx)
	if (debug)
		cprintf("[%08x] devpipe_write %08x %d rpos %d wpos %d\n",
			env->env_id, vpt[VPN(p)], n, p->p_rpos, p->p_wpos);

	buf = vbuf;
	for (i = 0; i < n; i++) {
  8025d9:	83 c7 01             	add    $0x1,%edi
  8025dc:	39 7d 10             	cmp    %edi,0x10(%ebp)
  8025df:	76 13                	jbe    8025f4 <devpipe_write+0x88>
		while (p->p_wpos >= p->p_rpos + sizeof(p->p_buf)) {
  8025e1:	8b 43 04             	mov    0x4(%ebx),%eax
  8025e4:	8b 13                	mov    (%ebx),%edx
  8025e6:	83 c2 20             	add    $0x20,%edx
  8025e9:	39 d0                	cmp    %edx,%eax
  8025eb:	73 a2                	jae    80258f <devpipe_write+0x23>
  8025ed:	eb ca                	jmp    8025b9 <devpipe_write+0x4d>
  8025ef:	bf 00 00 00 00       	mov    $0x0,%edi
		// wait to increment wpos until the byte is stored!
		p->p_buf[p->p_wpos % PIPEBUFSIZ] = buf[i];
		p->p_wpos++;
	}
	
	return i;
  8025f4:	89 f8                	mov    %edi,%eax
}
  8025f6:	83 c4 1c             	add    $0x1c,%esp
  8025f9:	5b                   	pop    %ebx
  8025fa:	5e                   	pop    %esi
  8025fb:	5f                   	pop    %edi
  8025fc:	5d                   	pop    %ebp
  8025fd:	c3                   	ret    

008025fe <devpipe_read>:
	return _pipeisclosed(fd, p);
}

static ssize_t
devpipe_read(struct Fd *fd, void *vbuf, size_t n)
{
  8025fe:	55                   	push   %ebp
  8025ff:	89 e5                	mov    %esp,%ebp
  802601:	83 ec 28             	sub    $0x28,%esp
  802604:	89 5d f4             	mov    %ebx,-0xc(%ebp)
  802607:	89 75 f8             	mov    %esi,-0x8(%ebp)
  80260a:	89 7d fc             	mov    %edi,-0x4(%ebp)
  80260d:	8b 7d 08             	mov    0x8(%ebp),%edi
	uint8_t *buf;
	size_t i;
	struct Pipe *p;

	p = (struct Pipe*)fd2data(fd);
  802610:	89 3c 24             	mov    %edi,(%esp)
  802613:	e8 68 f0 ff ff       	call   801680 <fd2data>
  802618:	89 c3                	mov    %eax,%ebx
	if (debug)
		cprintf("[%08x] devpipe_read %08x %d rpos %d wpos %d\n",
			env->env_id, vpt[VPN(p)], n, p->p_rpos, p->p_wpos);

	buf = vbuf;
	for (i = 0; i < n; i++) {
  80261a:	be 00 00 00 00       	mov    $0x0,%esi
  80261f:	83 7d 10 00          	cmpl   $0x0,0x10(%ebp)
  802623:	75 4c                	jne    802671 <devpipe_read+0x73>
  802625:	eb 5b                	jmp    802682 <devpipe_read+0x84>
		while (p->p_rpos == p->p_wpos) {
			// pipe is empty
			// if we got any data, return it
			if (i > 0)
				return i;
  802627:	89 f0                	mov    %esi,%eax
  802629:	eb 5e                	jmp    802689 <devpipe_read+0x8b>
			// if all the writers are gone, note eof
			if (_pipeisclosed(fd, p))
  80262b:	89 da                	mov    %ebx,%edx
  80262d:	89 f8                	mov    %edi,%eax
  80262f:	90                   	nop
  802630:	e8 cd fe ff ff       	call   802502 <_pipeisclosed>
  802635:	85 c0                	test   %eax,%eax
  802637:	74 07                	je     802640 <devpipe_read+0x42>
  802639:	b8 00 00 00 00       	mov    $0x0,%eax
  80263e:	eb 49                	jmp    802689 <devpipe_read+0x8b>
				return 0;
			// yield and see what happens
			if (debug)
				cprintf("devpipe_read yield\n");
			sys_yield();
  802640:	e8 60 eb ff ff       	call   8011a5 <sys_yield>
		cprintf("[%08x] devpipe_read %08x %d rpos %d wpos %d\n",
			env->env_id, vpt[VPN(p)], n, p->p_rpos, p->p_wpos);

	buf = vbuf;
	for (i = 0; i < n; i++) {
		while (p->p_rpos == p->p_wpos) {
  802645:	8b 03                	mov    (%ebx),%eax
  802647:	3b 43 04             	cmp    0x4(%ebx),%eax
  80264a:	74 df                	je     80262b <devpipe_read+0x2d>
				cprintf("devpipe_read yield\n");
			sys_yield();
		}
		// there's a byte.  take it.
		// wait to increment rpos until the byte is taken!
		buf[i] = p->p_buf[p->p_rpos % PIPEBUFSIZ];
  80264c:	89 c2                	mov    %eax,%edx
  80264e:	c1 fa 1f             	sar    $0x1f,%edx
  802651:	c1 ea 1b             	shr    $0x1b,%edx
  802654:	01 d0                	add    %edx,%eax
  802656:	83 e0 1f             	and    $0x1f,%eax
  802659:	29 d0                	sub    %edx,%eax
  80265b:	0f b6 44 03 08       	movzbl 0x8(%ebx,%eax,1),%eax
  802660:	8b 55 0c             	mov    0xc(%ebp),%edx
  802663:	88 04 32             	mov    %al,(%edx,%esi,1)
		p->p_rpos++;
  802666:	83 03 01             	addl   $0x1,(%ebx)
	if (debug)
		cprintf("[%08x] devpipe_read %08x %d rpos %d wpos %d\n",
			env->env_id, vpt[VPN(p)], n, p->p_rpos, p->p_wpos);

	buf = vbuf;
	for (i = 0; i < n; i++) {
  802669:	83 c6 01             	add    $0x1,%esi
  80266c:	39 75 10             	cmp    %esi,0x10(%ebp)
  80266f:	76 16                	jbe    802687 <devpipe_read+0x89>
		while (p->p_rpos == p->p_wpos) {
  802671:	8b 03                	mov    (%ebx),%eax
  802673:	3b 43 04             	cmp    0x4(%ebx),%eax
  802676:	75 d4                	jne    80264c <devpipe_read+0x4e>
			// pipe is empty
			// if we got any data, return it
			if (i > 0)
  802678:	85 f6                	test   %esi,%esi
  80267a:	75 ab                	jne    802627 <devpipe_read+0x29>
  80267c:	8d 74 26 00          	lea    0x0(%esi,%eiz,1),%esi
  802680:	eb a9                	jmp    80262b <devpipe_read+0x2d>
  802682:	be 00 00 00 00       	mov    $0x0,%esi
		// there's a byte.  take it.
		// wait to increment rpos until the byte is taken!
		buf[i] = p->p_buf[p->p_rpos % PIPEBUFSIZ];
		p->p_rpos++;
	}
	return i;
  802687:	89 f0                	mov    %esi,%eax
}
  802689:	8b 5d f4             	mov    -0xc(%ebp),%ebx
  80268c:	8b 75 f8             	mov    -0x8(%ebp),%esi
  80268f:	8b 7d fc             	mov    -0x4(%ebp),%edi
  802692:	89 ec                	mov    %ebp,%esp
  802694:	5d                   	pop    %ebp
  802695:	c3                   	ret    

00802696 <pipeisclosed>:
	}
}

int
pipeisclosed(int fdnum)
{
  802696:	55                   	push   %ebp
  802697:	89 e5                	mov    %esp,%ebp
  802699:	83 ec 28             	sub    $0x28,%esp
	struct Fd *fd;
	struct Pipe *p;
	int r;

	if ((r = fd_lookup(fdnum, &fd)) < 0)
  80269c:	8d 45 f4             	lea    -0xc(%ebp),%eax
  80269f:	89 44 24 04          	mov    %eax,0x4(%esp)
  8026a3:	8b 45 08             	mov    0x8(%ebp),%eax
  8026a6:	89 04 24             	mov    %eax,(%esp)
  8026a9:	e8 5f f0 ff ff       	call   80170d <fd_lookup>
  8026ae:	85 c0                	test   %eax,%eax
  8026b0:	78 15                	js     8026c7 <pipeisclosed+0x31>
		return r;
	p = (struct Pipe*) fd2data(fd);
  8026b2:	8b 45 f4             	mov    -0xc(%ebp),%eax
  8026b5:	89 04 24             	mov    %eax,(%esp)
  8026b8:	e8 c3 ef ff ff       	call   801680 <fd2data>
	return _pipeisclosed(fd, p);
  8026bd:	89 c2                	mov    %eax,%edx
  8026bf:	8b 45 f4             	mov    -0xc(%ebp),%eax
  8026c2:	e8 3b fe ff ff       	call   802502 <_pipeisclosed>
}
  8026c7:	c9                   	leave  
  8026c8:	c3                   	ret    

008026c9 <pipe>:
	uint8_t p_buf[PIPEBUFSIZ];	// data buffer
};

int
pipe(int pfd[2])
{
  8026c9:	55                   	push   %ebp
  8026ca:	89 e5                	mov    %esp,%ebp
  8026cc:	83 ec 48             	sub    $0x48,%esp
  8026cf:	89 5d f4             	mov    %ebx,-0xc(%ebp)
  8026d2:	89 75 f8             	mov    %esi,-0x8(%ebp)
  8026d5:	89 7d fc             	mov    %edi,-0x4(%ebp)
  8026d8:	8b 7d 08             	mov    0x8(%ebp),%edi
	int r;
	struct Fd *fd0, *fd1;
	void *va;

	// allocate the file descriptor table entries
	if ((r = fd_alloc(&fd0)) < 0
  8026db:	8d 45 e4             	lea    -0x1c(%ebp),%eax
  8026de:	89 04 24             	mov    %eax,(%esp)
  8026e1:	e8 b5 ef ff ff       	call   80169b <fd_alloc>
  8026e6:	89 c3                	mov    %eax,%ebx
  8026e8:	85 c0                	test   %eax,%eax
  8026ea:	0f 88 42 01 00 00    	js     802832 <pipe+0x169>
	    || (r = sys_page_alloc(0, fd0, PTE_P|PTE_W|PTE_U|PTE_SHARE)) < 0)
  8026f0:	c7 44 24 08 07 04 00 	movl   $0x407,0x8(%esp)
  8026f7:	00 
  8026f8:	8b 45 e4             	mov    -0x1c(%ebp),%eax
  8026fb:	89 44 24 04          	mov    %eax,0x4(%esp)
  8026ff:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  802706:	e8 3b ea ff ff       	call   801146 <sys_page_alloc>
  80270b:	89 c3                	mov    %eax,%ebx
	int r;
	struct Fd *fd0, *fd1;
	void *va;

	// allocate the file descriptor table entries
	if ((r = fd_alloc(&fd0)) < 0
  80270d:	85 c0                	test   %eax,%eax
  80270f:	0f 88 1d 01 00 00    	js     802832 <pipe+0x169>
	    || (r = sys_page_alloc(0, fd0, PTE_P|PTE_W|PTE_U|PTE_SHARE)) < 0)
		goto err;

	if ((r = fd_alloc(&fd1)) < 0
  802715:	8d 45 e0             	lea    -0x20(%ebp),%eax
  802718:	89 04 24             	mov    %eax,(%esp)
  80271b:	e8 7b ef ff ff       	call   80169b <fd_alloc>
  802720:	89 c3                	mov    %eax,%ebx
  802722:	85 c0                	test   %eax,%eax
  802724:	0f 88 f5 00 00 00    	js     80281f <pipe+0x156>
	    || (r = sys_page_alloc(0, fd1, PTE_P|PTE_W|PTE_U|PTE_SHARE)) < 0)
  80272a:	c7 44 24 08 07 04 00 	movl   $0x407,0x8(%esp)
  802731:	00 
  802732:	8b 45 e0             	mov    -0x20(%ebp),%eax
  802735:	89 44 24 04          	mov    %eax,0x4(%esp)
  802739:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  802740:	e8 01 ea ff ff       	call   801146 <sys_page_alloc>
  802745:	89 c3                	mov    %eax,%ebx
	// allocate the file descriptor table entries
	if ((r = fd_alloc(&fd0)) < 0
	    || (r = sys_page_alloc(0, fd0, PTE_P|PTE_W|PTE_U|PTE_SHARE)) < 0)
		goto err;

	if ((r = fd_alloc(&fd1)) < 0
  802747:	85 c0                	test   %eax,%eax
  802749:	0f 88 d0 00 00 00    	js     80281f <pipe+0x156>
	    || (r = sys_page_alloc(0, fd1, PTE_P|PTE_W|PTE_U|PTE_SHARE)) < 0)
		goto err1;

	// allocate the pipe structure as first data page in both
	va = fd2data(fd0);
  80274f:	8b 45 e4             	mov    -0x1c(%ebp),%eax
  802752:	89 04 24             	mov    %eax,(%esp)
  802755:	e8 26 ef ff ff       	call   801680 <fd2data>
  80275a:	89 c6                	mov    %eax,%esi
	if ((r = sys_page_alloc(0, va, PTE_P|PTE_W|PTE_U|PTE_SHARE)) < 0)
  80275c:	c7 44 24 08 07 04 00 	movl   $0x407,0x8(%esp)
  802763:	00 
  802764:	89 44 24 04          	mov    %eax,0x4(%esp)
  802768:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  80276f:	e8 d2 e9 ff ff       	call   801146 <sys_page_alloc>
  802774:	89 c3                	mov    %eax,%ebx
  802776:	85 c0                	test   %eax,%eax
  802778:	0f 88 8e 00 00 00    	js     80280c <pipe+0x143>
		goto err2;
	if ((r = sys_page_map(0, va, 0, fd2data(fd1), PTE_P|PTE_W|PTE_U|PTE_SHARE)) < 0)
  80277e:	8b 45 e0             	mov    -0x20(%ebp),%eax
  802781:	89 04 24             	mov    %eax,(%esp)
  802784:	e8 f7 ee ff ff       	call   801680 <fd2data>
  802789:	c7 44 24 10 07 04 00 	movl   $0x407,0x10(%esp)
  802790:	00 
  802791:	89 44 24 0c          	mov    %eax,0xc(%esp)
  802795:	c7 44 24 08 00 00 00 	movl   $0x0,0x8(%esp)
  80279c:	00 
  80279d:	89 74 24 04          	mov    %esi,0x4(%esp)
  8027a1:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  8027a8:	e8 3b e9 ff ff       	call   8010e8 <sys_page_map>
  8027ad:	89 c3                	mov    %eax,%ebx
  8027af:	85 c0                	test   %eax,%eax
  8027b1:	78 49                	js     8027fc <pipe+0x133>
		goto err3;

	// set up fd structures
	fd0->fd_dev_id = devpipe.dev_id;
  8027b3:	b8 3c 70 80 00       	mov    $0x80703c,%eax
  8027b8:	8b 08                	mov    (%eax),%ecx
  8027ba:	8b 55 e4             	mov    -0x1c(%ebp),%edx
  8027bd:	89 0a                	mov    %ecx,(%edx)
	fd0->fd_omode = O_RDONLY;
  8027bf:	8b 55 e4             	mov    -0x1c(%ebp),%edx
  8027c2:	c7 42 08 00 00 00 00 	movl   $0x0,0x8(%edx)

	fd1->fd_dev_id = devpipe.dev_id;
  8027c9:	8b 10                	mov    (%eax),%edx
  8027cb:	8b 45 e0             	mov    -0x20(%ebp),%eax
  8027ce:	89 10                	mov    %edx,(%eax)
	fd1->fd_omode = O_WRONLY;
  8027d0:	8b 45 e0             	mov    -0x20(%ebp),%eax
  8027d3:	c7 40 08 01 00 00 00 	movl   $0x1,0x8(%eax)

	if (debug)
		cprintf("[%08x] pipecreate %08x\n", env->env_id, vpt[VPN(va)]);

	pfd[0] = fd2num(fd0);
  8027da:	8b 45 e4             	mov    -0x1c(%ebp),%eax
  8027dd:	89 04 24             	mov    %eax,(%esp)
  8027e0:	e8 8b ee ff ff       	call   801670 <fd2num>
  8027e5:	89 07                	mov    %eax,(%edi)
	pfd[1] = fd2num(fd1);
  8027e7:	8b 45 e0             	mov    -0x20(%ebp),%eax
  8027ea:	89 04 24             	mov    %eax,(%esp)
  8027ed:	e8 7e ee ff ff       	call   801670 <fd2num>
  8027f2:	89 47 04             	mov    %eax,0x4(%edi)
  8027f5:	bb 00 00 00 00       	mov    $0x0,%ebx
	return 0;
  8027fa:	eb 36                	jmp    802832 <pipe+0x169>

    err3:
	sys_page_unmap(0, va);
  8027fc:	89 74 24 04          	mov    %esi,0x4(%esp)
  802800:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  802807:	e8 7e e8 ff ff       	call   80108a <sys_page_unmap>
    err2:
	sys_page_unmap(0, fd1);
  80280c:	8b 45 e0             	mov    -0x20(%ebp),%eax
  80280f:	89 44 24 04          	mov    %eax,0x4(%esp)
  802813:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  80281a:	e8 6b e8 ff ff       	call   80108a <sys_page_unmap>
    err1:
	sys_page_unmap(0, fd0);
  80281f:	8b 45 e4             	mov    -0x1c(%ebp),%eax
  802822:	89 44 24 04          	mov    %eax,0x4(%esp)
  802826:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  80282d:	e8 58 e8 ff ff       	call   80108a <sys_page_unmap>
    err:
	return r;
}
  802832:	89 d8                	mov    %ebx,%eax
  802834:	8b 5d f4             	mov    -0xc(%ebp),%ebx
  802837:	8b 75 f8             	mov    -0x8(%ebp),%esi
  80283a:	8b 7d fc             	mov    -0x4(%ebp),%edi
  80283d:	89 ec                	mov    %ebp,%esp
  80283f:	5d                   	pop    %ebp
  802840:	c3                   	ret    
	...

00802850 <devcons_close>:
	return tot;
}

static int
devcons_close(struct Fd *fd)
{
  802850:	55                   	push   %ebp
  802851:	89 e5                	mov    %esp,%ebp
	USED(fd);

	return 0;
}
  802853:	b8 00 00 00 00       	mov    $0x0,%eax
  802858:	5d                   	pop    %ebp
  802859:	c3                   	ret    

0080285a <devcons_stat>:

static int
devcons_stat(struct Fd *fd, struct Stat *stat)
{
  80285a:	55                   	push   %ebp
  80285b:	89 e5                	mov    %esp,%ebp
  80285d:	83 ec 18             	sub    $0x18,%esp
	strcpy(stat->st_name, "<cons>");
  802860:	c7 44 24 04 35 35 80 	movl   $0x803535,0x4(%esp)
  802867:	00 
  802868:	8b 45 0c             	mov    0xc(%ebp),%eax
  80286b:	89 04 24             	mov    %eax,(%esp)
  80286e:	e8 77 e1 ff ff       	call   8009ea <strcpy>
	return 0;
}
  802873:	b8 00 00 00 00       	mov    $0x0,%eax
  802878:	c9                   	leave  
  802879:	c3                   	ret    

0080287a <devcons_write>:
	return 1;
}

static ssize_t
devcons_write(struct Fd *fd, const void *vbuf, size_t n)
{
  80287a:	55                   	push   %ebp
  80287b:	89 e5                	mov    %esp,%ebp
  80287d:	57                   	push   %edi
  80287e:	56                   	push   %esi
  80287f:	53                   	push   %ebx
  802880:	81 ec 9c 00 00 00    	sub    $0x9c,%esp
	int tot, m;
	char buf[128];

	// mistake: have to nul-terminate arg to sys_cputs, 
	// so we have to copy vbuf into buf in chunks and nul-terminate.
	for (tot = 0; tot < n; tot += m) {
  802886:	b8 00 00 00 00       	mov    $0x0,%eax
  80288b:	be 00 00 00 00       	mov    $0x0,%esi
  802890:	83 7d 10 00          	cmpl   $0x0,0x10(%ebp)
  802894:	74 41                	je     8028d7 <devcons_write+0x5d>
		m = n - tot;
		if (m > sizeof(buf) - 1)
			m = sizeof(buf) - 1;
		memmove(buf, (char*)vbuf + tot, m);
  802896:	8d bd 68 ff ff ff    	lea    -0x98(%ebp),%edi
	char buf[128];

	// mistake: have to nul-terminate arg to sys_cputs, 
	// so we have to copy vbuf into buf in chunks and nul-terminate.
	for (tot = 0; tot < n; tot += m) {
		m = n - tot;
  80289c:	8b 5d 10             	mov    0x10(%ebp),%ebx
  80289f:	29 c3                	sub    %eax,%ebx
		if (m > sizeof(buf) - 1)
  8028a1:	81 fb 80 00 00 00    	cmp    $0x80,%ebx
  8028a7:	ba 7f 00 00 00       	mov    $0x7f,%edx
  8028ac:	0f 43 da             	cmovae %edx,%ebx
			m = sizeof(buf) - 1;
		memmove(buf, (char*)vbuf + tot, m);
  8028af:	89 5c 24 08          	mov    %ebx,0x8(%esp)
  8028b3:	03 45 0c             	add    0xc(%ebp),%eax
  8028b6:	89 44 24 04          	mov    %eax,0x4(%esp)
  8028ba:	89 3c 24             	mov    %edi,(%esp)
  8028bd:	e8 e3 e2 ff ff       	call   800ba5 <memmove>
		sys_cputs(buf, m);
  8028c2:	89 5c 24 04          	mov    %ebx,0x4(%esp)
  8028c6:	89 3c 24             	mov    %edi,(%esp)
  8028c9:	e8 12 e5 ff ff       	call   800de0 <sys_cputs>
	int tot, m;
	char buf[128];

	// mistake: have to nul-terminate arg to sys_cputs, 
	// so we have to copy vbuf into buf in chunks and nul-terminate.
	for (tot = 0; tot < n; tot += m) {
  8028ce:	01 de                	add    %ebx,%esi
  8028d0:	89 f0                	mov    %esi,%eax
  8028d2:	3b 75 10             	cmp    0x10(%ebp),%esi
  8028d5:	72 c5                	jb     80289c <devcons_write+0x22>
			m = sizeof(buf) - 1;
		memmove(buf, (char*)vbuf + tot, m);
		sys_cputs(buf, m);
	}
	return tot;
}
  8028d7:	89 f0                	mov    %esi,%eax
  8028d9:	81 c4 9c 00 00 00    	add    $0x9c,%esp
  8028df:	5b                   	pop    %ebx
  8028e0:	5e                   	pop    %esi
  8028e1:	5f                   	pop    %edi
  8028e2:	5d                   	pop    %ebp
  8028e3:	c3                   	ret    

008028e4 <cputchar>:
#include <inc/string.h>
#include <inc/lib.h>

void
cputchar(int ch)
{
  8028e4:	55                   	push   %ebp
  8028e5:	89 e5                	mov    %esp,%ebp
  8028e7:	83 ec 28             	sub    $0x28,%esp
	char c = ch;
  8028ea:	8b 45 08             	mov    0x8(%ebp),%eax
  8028ed:	88 45 f7             	mov    %al,-0x9(%ebp)

	// Unlike standard Unix's putchar,
	// the cputchar function _always_ outputs to the system console.
	sys_cputs(&c, 1);
  8028f0:	c7 44 24 04 01 00 00 	movl   $0x1,0x4(%esp)
  8028f7:	00 
  8028f8:	8d 45 f7             	lea    -0x9(%ebp),%eax
  8028fb:	89 04 24             	mov    %eax,(%esp)
  8028fe:	e8 dd e4 ff ff       	call   800de0 <sys_cputs>
}
  802903:	c9                   	leave  
  802904:	c3                   	ret    

00802905 <devcons_read>:
	return fd2num(fd);
}

static ssize_t
devcons_read(struct Fd *fd, void *vbuf, size_t n)
{
  802905:	55                   	push   %ebp
  802906:	89 e5                	mov    %esp,%ebp
  802908:	83 ec 08             	sub    $0x8,%esp
	int c;

	if (n == 0)
  80290b:	83 7d 10 00          	cmpl   $0x0,0x10(%ebp)
  80290f:	75 07                	jne    802918 <devcons_read+0x13>
  802911:	eb 2d                	jmp    802940 <devcons_read+0x3b>
		return 0;
	while ((c = sys_cgetc()) == 0)
		sys_yield();
  802913:	e8 8d e8 ff ff       	call   8011a5 <sys_yield>
{
	int c;

	if (n == 0)
		return 0;
	while ((c = sys_cgetc()) == 0)
  802918:	90                   	nop
  802919:	8d b4 26 00 00 00 00 	lea    0x0(%esi,%eiz,1),%esi
  802920:	e8 87 e4 ff ff       	call   800dac <sys_cgetc>
  802925:	85 c0                	test   %eax,%eax
  802927:	74 ea                	je     802913 <devcons_read+0xe>
  802929:	89 c2                	mov    %eax,%edx
		sys_yield();
	if (c < 0)
  80292b:	85 c0                	test   %eax,%eax
  80292d:	78 16                	js     802945 <devcons_read+0x40>
		return c;
	if (c == 0x04)	// ctl-d is eof
  80292f:	83 f8 04             	cmp    $0x4,%eax
  802932:	74 0c                	je     802940 <devcons_read+0x3b>
		return 0;
	*(char*)vbuf = c;
  802934:	8b 45 0c             	mov    0xc(%ebp),%eax
  802937:	88 10                	mov    %dl,(%eax)
  802939:	b8 01 00 00 00       	mov    $0x1,%eax
	return 1;
  80293e:	eb 05                	jmp    802945 <devcons_read+0x40>
  802940:	b8 00 00 00 00       	mov    $0x0,%eax
}
  802945:	c9                   	leave  
  802946:	c3                   	ret    

00802947 <opencons>:
	return fd->fd_dev_id == devcons.dev_id;
}

int
opencons(void)
{
  802947:	55                   	push   %ebp
  802948:	89 e5                	mov    %esp,%ebp
  80294a:	83 ec 28             	sub    $0x28,%esp
	int r;
	struct Fd* fd;

	if ((r = fd_alloc(&fd)) < 0)
  80294d:	8d 45 f4             	lea    -0xc(%ebp),%eax
  802950:	89 04 24             	mov    %eax,(%esp)
  802953:	e8 43 ed ff ff       	call   80169b <fd_alloc>
  802958:	85 c0                	test   %eax,%eax
  80295a:	78 3f                	js     80299b <opencons+0x54>
		return r;
	if ((r = sys_page_alloc(0, fd, PTE_P|PTE_U|PTE_W|PTE_SHARE)) < 0)
  80295c:	c7 44 24 08 07 04 00 	movl   $0x407,0x8(%esp)
  802963:	00 
  802964:	8b 45 f4             	mov    -0xc(%ebp),%eax
  802967:	89 44 24 04          	mov    %eax,0x4(%esp)
  80296b:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  802972:	e8 cf e7 ff ff       	call   801146 <sys_page_alloc>
  802977:	85 c0                	test   %eax,%eax
  802979:	78 20                	js     80299b <opencons+0x54>
		return r;
	fd->fd_dev_id = devcons.dev_id;
  80297b:	8b 15 58 70 80 00    	mov    0x807058,%edx
  802981:	8b 45 f4             	mov    -0xc(%ebp),%eax
  802984:	89 10                	mov    %edx,(%eax)
	fd->fd_omode = O_RDWR;
  802986:	8b 45 f4             	mov    -0xc(%ebp),%eax
  802989:	c7 40 08 02 00 00 00 	movl   $0x2,0x8(%eax)
	return fd2num(fd);
  802990:	8b 45 f4             	mov    -0xc(%ebp),%eax
  802993:	89 04 24             	mov    %eax,(%esp)
  802996:	e8 d5 ec ff ff       	call   801670 <fd2num>
}
  80299b:	c9                   	leave  
  80299c:	c3                   	ret    

0080299d <iscons>:
	.dev_stat =	devcons_stat
};

int
iscons(int fdnum)
{
  80299d:	55                   	push   %ebp
  80299e:	89 e5                	mov    %esp,%ebp
  8029a0:	83 ec 28             	sub    $0x28,%esp
	int r;
	struct Fd *fd;

	if ((r = fd_lookup(fdnum, &fd)) < 0)
  8029a3:	8d 45 f4             	lea    -0xc(%ebp),%eax
  8029a6:	89 44 24 04          	mov    %eax,0x4(%esp)
  8029aa:	8b 45 08             	mov    0x8(%ebp),%eax
  8029ad:	89 04 24             	mov    %eax,(%esp)
  8029b0:	e8 58 ed ff ff       	call   80170d <fd_lookup>
  8029b5:	85 c0                	test   %eax,%eax
  8029b7:	78 11                	js     8029ca <iscons+0x2d>
		return r;
	return fd->fd_dev_id == devcons.dev_id;
  8029b9:	8b 45 f4             	mov    -0xc(%ebp),%eax
  8029bc:	8b 00                	mov    (%eax),%eax
  8029be:	3b 05 58 70 80 00    	cmp    0x807058,%eax
  8029c4:	0f 94 c0             	sete   %al
  8029c7:	0f b6 c0             	movzbl %al,%eax
}
  8029ca:	c9                   	leave  
  8029cb:	c3                   	ret    

008029cc <getchar>:
	sys_cputs(&c, 1);
}

int
getchar(void)
{
  8029cc:	55                   	push   %ebp
  8029cd:	89 e5                	mov    %esp,%ebp
  8029cf:	83 ec 28             	sub    $0x28,%esp
	int r;

	// JOS does, however, support standard _input_ redirection,
	// allowing the user to redirect script files to the shell and such.
	// getchar() reads a character from file descriptor 0.
	r = read(0, &c, 1);
  8029d2:	c7 44 24 08 01 00 00 	movl   $0x1,0x8(%esp)
  8029d9:	00 
  8029da:	8d 45 f7             	lea    -0x9(%ebp),%eax
  8029dd:	89 44 24 04          	mov    %eax,0x4(%esp)
  8029e1:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  8029e8:	e8 86 ef ff ff       	call   801973 <read>
	if (r < 0)
  8029ed:	85 c0                	test   %eax,%eax
  8029ef:	78 0f                	js     802a00 <getchar+0x34>
		return r;
	if (r < 1)
  8029f1:	85 c0                	test   %eax,%eax
  8029f3:	7f 07                	jg     8029fc <getchar+0x30>
  8029f5:	b8 f8 ff ff ff       	mov    $0xfffffff8,%eax
  8029fa:	eb 04                	jmp    802a00 <getchar+0x34>
		return -E_EOF;
	return c;
  8029fc:	0f b6 45 f7          	movzbl -0x9(%ebp),%eax
}
  802a00:	c9                   	leave  
  802a01:	c3                   	ret    
	...

00802a04 <set_pgfault_handler>:
// at UXSTACKTOP), and tell the kernel to call the assembly-language
// _pgfault_upcall routine when a page fault occurs.
//
void
set_pgfault_handler(void (*handler)(struct UTrapframe *utf))
{
  802a04:	55                   	push   %ebp
  802a05:	89 e5                	mov    %esp,%ebp
  802a07:	83 ec 18             	sub    $0x18,%esp
	int r;

	if (_pgfault_handler == NULL) {
  802a0a:	83 3d 7c 70 80 00 00 	cmpl   $0x0,0x80707c
  802a11:	75 55                	jne    802a68 <set_pgfault_handler+0x64>
		// First time through!
		// LAB 4: Your code here.
        if (sys_page_alloc(sys_getenvid(), (void *)(UXSTACKTOP-PGSIZE), PTE_P|PTE_U|PTE_W))
  802a13:	e8 c1 e7 ff ff       	call   8011d9 <sys_getenvid>
  802a18:	c7 44 24 08 07 00 00 	movl   $0x7,0x8(%esp)
  802a1f:	00 
  802a20:	c7 44 24 04 00 f0 bf 	movl   $0xeebff000,0x4(%esp)
  802a27:	ee 
  802a28:	89 04 24             	mov    %eax,(%esp)
  802a2b:	e8 16 e7 ff ff       	call   801146 <sys_page_alloc>
  802a30:	85 c0                	test   %eax,%eax
  802a32:	74 1c                	je     802a50 <set_pgfault_handler+0x4c>
		    panic("set_pgfault_handler not implemented");
  802a34:	c7 44 24 08 44 35 80 	movl   $0x803544,0x8(%esp)
  802a3b:	00 
  802a3c:	c7 44 24 04 21 00 00 	movl   $0x21,0x4(%esp)
  802a43:	00 
  802a44:	c7 04 24 68 35 80 00 	movl   $0x803568,(%esp)
  802a4b:	e8 08 d8 ff ff       	call   800258 <_panic>
        sys_env_set_pgfault_upcall(env->env_id, _pgfault_upcall);
  802a50:	a1 74 70 80 00       	mov    0x807074,%eax
  802a55:	8b 40 4c             	mov    0x4c(%eax),%eax
  802a58:	c7 44 24 04 74 2a 80 	movl   $0x802a74,0x4(%esp)
  802a5f:	00 
  802a60:	89 04 24             	mov    %eax,(%esp)
  802a63:	e8 08 e5 ff ff       	call   800f70 <sys_env_set_pgfault_upcall>
	}

	// Save handler pointer for assembly to call.
	_pgfault_handler = handler;
  802a68:	8b 45 08             	mov    0x8(%ebp),%eax
  802a6b:	a3 7c 70 80 00       	mov    %eax,0x80707c
}
  802a70:	c9                   	leave  
  802a71:	c3                   	ret    
	...

00802a74 <_pgfault_upcall>:

.text
.globl _pgfault_upcall
_pgfault_upcall:
	// Call the C page fault handler.
	pushl %esp			// function argument: pointer to UTF
  802a74:	54                   	push   %esp
	movl _pgfault_handler, %eax
  802a75:	a1 7c 70 80 00       	mov    0x80707c,%eax
	call *%eax
  802a7a:	ff d0                	call   *%eax
	addl $4, %esp			// pop function argument
  802a7c:	83 c4 04             	add    $0x4,%esp
	// may find that you have to rearrange your code in non-obvious
	// ways as registers become unavailable as scratch space.
	//
	// LAB 4: Your code here.

    subl $4, 48(%esp)
  802a7f:	83 6c 24 30 04       	subl   $0x4,0x30(%esp)
    movl 48(%esp), %eax
  802a84:	8b 44 24 30          	mov    0x30(%esp),%eax
    movl 40(%esp), %ebx
  802a88:	8b 5c 24 28          	mov    0x28(%esp),%ebx
    movl %ebx, (%eax)
  802a8c:	89 18                	mov    %ebx,(%eax)
    
	// Restore the trap-time registers.  After you do this, you
	// can no longer modify any general-purpose registers.
	// LAB 4: Your code here.
    addl $8, %esp
  802a8e:	83 c4 08             	add    $0x8,%esp
    popal
  802a91:	61                   	popa   
   
	// Restore eflags from the stack.  After you do this, you can
	// no longer use arithmetic operations or anything else that
	// modifies eflags.
	// LAB 4: Your code here.
    pushl 4(%esp)
  802a92:	ff 74 24 04          	pushl  0x4(%esp)
    popf
  802a96:	9d                   	popf   

	// Switch back to the adjusted trap-time stack.
	// LAB 4: Your code here.
    movl 8(%esp), %esp
  802a97:	8b 64 24 08          	mov    0x8(%esp),%esp

	// Return to re-execute the instruction that faulted.
	// LAB 4: Your code here.
    ret
  802a9b:	c3                   	ret    
  802a9c:	00 00                	add    %al,(%eax)
	...

00802aa0 <ipc_send>:
//   Use sys_yield() to be CPU-friendly.
//   If 'pg' is null, pass sys_ipc_recv a value that it will understand
//   as meaning "no page".  (Zero is not the right value.)
void
ipc_send(envid_t to_env, uint32_t val, void *pg, int perm)
{
  802aa0:	55                   	push   %ebp
  802aa1:	89 e5                	mov    %esp,%ebp
  802aa3:	57                   	push   %edi
  802aa4:	56                   	push   %esi
  802aa5:	53                   	push   %ebx
  802aa6:	83 ec 2c             	sub    $0x2c,%esp
  802aa9:	8b 75 08             	mov    0x8(%ebp),%esi
  802aac:	8b 7d 0c             	mov    0xc(%ebp),%edi
  802aaf:	8b 5d 10             	mov    0x10(%ebp),%ebx
  int r   = 0;
  while (1) {
    if ((r=sys_ipc_try_send(to_env, val, (pg==NULL?(void *)UTOP:pg), perm)) == -E_IPC_NOT_RECV)
  802ab2:	85 db                	test   %ebx,%ebx
  802ab4:	b8 00 00 c0 ee       	mov    $0xeec00000,%eax
  802ab9:	0f 45 c3             	cmovne %ebx,%eax
  802abc:	8b 55 14             	mov    0x14(%ebp),%edx
  802abf:	89 54 24 0c          	mov    %edx,0xc(%esp)
  802ac3:	89 44 24 08          	mov    %eax,0x8(%esp)
  802ac7:	89 7c 24 04          	mov    %edi,0x4(%esp)
  802acb:	89 34 24             	mov    %esi,(%esp)
  802ace:	e8 3d e4 ff ff       	call   800f10 <sys_ipc_try_send>
  802ad3:	83 f8 f9             	cmp    $0xfffffff9,%eax
  802ad6:	75 0a                	jne    802ae2 <ipc_send+0x42>
      sys_yield();
  802ad8:	e8 c8 e6 ff ff       	call   8011a5 <sys_yield>
    else if (r < 0)
      panic("ipc_send to [%x] failed. Error: %x\n", to_env, r);
    else
      return;
  }
  802add:	8d 76 00             	lea    0x0(%esi),%esi
  802ae0:	eb d0                	jmp    802ab2 <ipc_send+0x12>
{
  int r   = 0;
  while (1) {
    if ((r=sys_ipc_try_send(to_env, val, (pg==NULL?(void *)UTOP:pg), perm)) == -E_IPC_NOT_RECV)
      sys_yield();
    else if (r < 0)
  802ae2:	85 c0                	test   %eax,%eax
  802ae4:	79 24                	jns    802b0a <ipc_send+0x6a>
      panic("ipc_send to [%x] failed. Error: %x\n", to_env, r);
  802ae6:	89 44 24 10          	mov    %eax,0x10(%esp)
  802aea:	89 74 24 0c          	mov    %esi,0xc(%esp)
  802aee:	c7 44 24 08 78 35 80 	movl   $0x803578,0x8(%esp)
  802af5:	00 
  802af6:	c7 44 24 04 36 00 00 	movl   $0x36,0x4(%esp)
  802afd:	00 
  802afe:	c7 04 24 9c 35 80 00 	movl   $0x80359c,(%esp)
  802b05:	e8 4e d7 ff ff       	call   800258 <_panic>
    else
      return;
  }
}
  802b0a:	83 c4 2c             	add    $0x2c,%esp
  802b0d:	5b                   	pop    %ebx
  802b0e:	5e                   	pop    %esi
  802b0f:	5f                   	pop    %edi
  802b10:	5d                   	pop    %ebp
  802b11:	c3                   	ret    

00802b12 <ipc_recv>:
//   If 'pg' is null, pass sys_ipc_recv a value that it will understand
//   as meaning "no page".  (Zero is not the right value, since that's
//   a perfectly valid place to map a page.)
int32_t
ipc_recv(envid_t *from_env_store, void *pg, int *perm_store)
{
  802b12:	55                   	push   %ebp
  802b13:	89 e5                	mov    %esp,%ebp
  802b15:	56                   	push   %esi
  802b16:	53                   	push   %ebx
  802b17:	83 ec 10             	sub    $0x10,%esp
  802b1a:	8b 5d 08             	mov    0x8(%ebp),%ebx
  802b1d:	8b 45 0c             	mov    0xc(%ebp),%eax
  802b20:	8b 75 10             	mov    0x10(%ebp),%esi
  int r;
  if ((r=sys_ipc_recv((pg==NULL?(void *)UTOP:pg)))<0)
  802b23:	85 c0                	test   %eax,%eax
  802b25:	ba 00 00 c0 ee       	mov    $0xeec00000,%edx
  802b2a:	0f 44 c2             	cmove  %edx,%eax
  802b2d:	89 04 24             	mov    %eax,(%esp)
  802b30:	e8 7e e3 ff ff       	call   800eb3 <sys_ipc_recv>
  802b35:	85 c0                	test   %eax,%eax
  802b37:	78 24                	js     802b5d <ipc_recv+0x4b>
    return r;

  if (from_env_store)
  802b39:	85 db                	test   %ebx,%ebx
  802b3b:	74 0a                	je     802b47 <ipc_recv+0x35>
    *from_env_store = env->env_ipc_from;
  802b3d:	a1 74 70 80 00       	mov    0x807074,%eax
  802b42:	8b 40 74             	mov    0x74(%eax),%eax
  802b45:	89 03                	mov    %eax,(%ebx)

  if (perm_store)
  802b47:	85 f6                	test   %esi,%esi
  802b49:	74 0a                	je     802b55 <ipc_recv+0x43>
    *perm_store     = env->env_ipc_perm;
  802b4b:	a1 74 70 80 00       	mov    0x807074,%eax
  802b50:	8b 40 78             	mov    0x78(%eax),%eax
  802b53:	89 06                	mov    %eax,(%esi)

  return env->env_ipc_value;
  802b55:	a1 74 70 80 00       	mov    0x807074,%eax
  802b5a:	8b 40 70             	mov    0x70(%eax),%eax
}
  802b5d:	83 c4 10             	add    $0x10,%esp
  802b60:	5b                   	pop    %ebx
  802b61:	5e                   	pop    %esi
  802b62:	5d                   	pop    %ebp
  802b63:	c3                   	ret    

00802b64 <pageref>:
#include <inc/lib.h>

int
pageref(void *v)
{
  802b64:	55                   	push   %ebp
  802b65:	89 e5                	mov    %esp,%ebp
	pte_t pte;

	if (!(vpd[PDX(v)] & PTE_P))
  802b67:	8b 45 08             	mov    0x8(%ebp),%eax
  802b6a:	89 c2                	mov    %eax,%edx
  802b6c:	c1 ea 16             	shr    $0x16,%edx
  802b6f:	8b 14 95 00 d0 7b ef 	mov    -0x10843000(,%edx,4),%edx
  802b76:	f6 c2 01             	test   $0x1,%dl
  802b79:	74 26                	je     802ba1 <pageref+0x3d>
		return 0;
	pte = vpt[VPN(v)];
  802b7b:	c1 e8 0c             	shr    $0xc,%eax
  802b7e:	8b 04 85 00 00 40 ef 	mov    -0x10c00000(,%eax,4),%eax
	if (!(pte & PTE_P))
  802b85:	a8 01                	test   $0x1,%al
  802b87:	74 18                	je     802ba1 <pageref+0x3d>
		return 0;
	return pages[PPN(pte)].pp_ref;
  802b89:	c1 e8 0c             	shr    $0xc,%eax
  802b8c:	8d 14 40             	lea    (%eax,%eax,2),%edx
  802b8f:	c1 e2 02             	shl    $0x2,%edx
  802b92:	b8 00 00 00 ef       	mov    $0xef000000,%eax
  802b97:	0f b7 44 02 08       	movzwl 0x8(%edx,%eax,1),%eax
  802b9c:	0f b7 c0             	movzwl %ax,%eax
  802b9f:	eb 05                	jmp    802ba6 <pageref+0x42>
  802ba1:	b8 00 00 00 00       	mov    $0x0,%eax
}
  802ba6:	5d                   	pop    %ebp
  802ba7:	c3                   	ret    
	...

00802bb0 <__udivdi3>:
  802bb0:	55                   	push   %ebp
  802bb1:	89 e5                	mov    %esp,%ebp
  802bb3:	57                   	push   %edi
  802bb4:	56                   	push   %esi
  802bb5:	83 ec 10             	sub    $0x10,%esp
  802bb8:	8b 45 14             	mov    0x14(%ebp),%eax
  802bbb:	8b 55 08             	mov    0x8(%ebp),%edx
  802bbe:	8b 75 10             	mov    0x10(%ebp),%esi
  802bc1:	8b 7d 0c             	mov    0xc(%ebp),%edi
  802bc4:	85 c0                	test   %eax,%eax
  802bc6:	89 55 f0             	mov    %edx,-0x10(%ebp)
  802bc9:	75 35                	jne    802c00 <__udivdi3+0x50>
  802bcb:	39 fe                	cmp    %edi,%esi
  802bcd:	77 61                	ja     802c30 <__udivdi3+0x80>
  802bcf:	85 f6                	test   %esi,%esi
  802bd1:	75 0b                	jne    802bde <__udivdi3+0x2e>
  802bd3:	b8 01 00 00 00       	mov    $0x1,%eax
  802bd8:	31 d2                	xor    %edx,%edx
  802bda:	f7 f6                	div    %esi
  802bdc:	89 c6                	mov    %eax,%esi
  802bde:	8b 4d f0             	mov    -0x10(%ebp),%ecx
  802be1:	31 d2                	xor    %edx,%edx
  802be3:	89 f8                	mov    %edi,%eax
  802be5:	f7 f6                	div    %esi
  802be7:	89 c7                	mov    %eax,%edi
  802be9:	89 c8                	mov    %ecx,%eax
  802beb:	f7 f6                	div    %esi
  802bed:	89 c1                	mov    %eax,%ecx
  802bef:	89 fa                	mov    %edi,%edx
  802bf1:	89 c8                	mov    %ecx,%eax
  802bf3:	83 c4 10             	add    $0x10,%esp
  802bf6:	5e                   	pop    %esi
  802bf7:	5f                   	pop    %edi
  802bf8:	5d                   	pop    %ebp
  802bf9:	c3                   	ret    
  802bfa:	8d b6 00 00 00 00    	lea    0x0(%esi),%esi
  802c00:	39 f8                	cmp    %edi,%eax
  802c02:	77 1c                	ja     802c20 <__udivdi3+0x70>
  802c04:	0f bd d0             	bsr    %eax,%edx
  802c07:	83 f2 1f             	xor    $0x1f,%edx
  802c0a:	89 55 f4             	mov    %edx,-0xc(%ebp)
  802c0d:	75 39                	jne    802c48 <__udivdi3+0x98>
  802c0f:	3b 75 f0             	cmp    -0x10(%ebp),%esi
  802c12:	0f 86 a0 00 00 00    	jbe    802cb8 <__udivdi3+0x108>
  802c18:	39 f8                	cmp    %edi,%eax
  802c1a:	0f 82 98 00 00 00    	jb     802cb8 <__udivdi3+0x108>
  802c20:	31 ff                	xor    %edi,%edi
  802c22:	31 c9                	xor    %ecx,%ecx
  802c24:	89 c8                	mov    %ecx,%eax
  802c26:	89 fa                	mov    %edi,%edx
  802c28:	83 c4 10             	add    $0x10,%esp
  802c2b:	5e                   	pop    %esi
  802c2c:	5f                   	pop    %edi
  802c2d:	5d                   	pop    %ebp
  802c2e:	c3                   	ret    
  802c2f:	90                   	nop
  802c30:	89 d1                	mov    %edx,%ecx
  802c32:	89 fa                	mov    %edi,%edx
  802c34:	89 c8                	mov    %ecx,%eax
  802c36:	31 ff                	xor    %edi,%edi
  802c38:	f7 f6                	div    %esi
  802c3a:	89 c1                	mov    %eax,%ecx
  802c3c:	89 fa                	mov    %edi,%edx
  802c3e:	89 c8                	mov    %ecx,%eax
  802c40:	83 c4 10             	add    $0x10,%esp
  802c43:	5e                   	pop    %esi
  802c44:	5f                   	pop    %edi
  802c45:	5d                   	pop    %ebp
  802c46:	c3                   	ret    
  802c47:	90                   	nop
  802c48:	0f b6 4d f4          	movzbl -0xc(%ebp),%ecx
  802c4c:	89 f2                	mov    %esi,%edx
  802c4e:	d3 e0                	shl    %cl,%eax
  802c50:	89 45 ec             	mov    %eax,-0x14(%ebp)
  802c53:	b8 20 00 00 00       	mov    $0x20,%eax
  802c58:	2b 45 f4             	sub    -0xc(%ebp),%eax
  802c5b:	89 c1                	mov    %eax,%ecx
  802c5d:	d3 ea                	shr    %cl,%edx
  802c5f:	0f b6 4d f4          	movzbl -0xc(%ebp),%ecx
  802c63:	0b 55 ec             	or     -0x14(%ebp),%edx
  802c66:	d3 e6                	shl    %cl,%esi
  802c68:	89 c1                	mov    %eax,%ecx
  802c6a:	89 75 e8             	mov    %esi,-0x18(%ebp)
  802c6d:	89 fe                	mov    %edi,%esi
  802c6f:	d3 ee                	shr    %cl,%esi
  802c71:	0f b6 4d f4          	movzbl -0xc(%ebp),%ecx
  802c75:	89 55 ec             	mov    %edx,-0x14(%ebp)
  802c78:	8b 55 f0             	mov    -0x10(%ebp),%edx
  802c7b:	d3 e7                	shl    %cl,%edi
  802c7d:	89 c1                	mov    %eax,%ecx
  802c7f:	d3 ea                	shr    %cl,%edx
  802c81:	09 d7                	or     %edx,%edi
  802c83:	89 f2                	mov    %esi,%edx
  802c85:	89 f8                	mov    %edi,%eax
  802c87:	f7 75 ec             	divl   -0x14(%ebp)
  802c8a:	89 d6                	mov    %edx,%esi
  802c8c:	89 c7                	mov    %eax,%edi
  802c8e:	f7 65 e8             	mull   -0x18(%ebp)
  802c91:	39 d6                	cmp    %edx,%esi
  802c93:	89 55 ec             	mov    %edx,-0x14(%ebp)
  802c96:	72 30                	jb     802cc8 <__udivdi3+0x118>
  802c98:	8b 55 f0             	mov    -0x10(%ebp),%edx
  802c9b:	0f b6 4d f4          	movzbl -0xc(%ebp),%ecx
  802c9f:	d3 e2                	shl    %cl,%edx
  802ca1:	39 c2                	cmp    %eax,%edx
  802ca3:	73 05                	jae    802caa <__udivdi3+0xfa>
  802ca5:	3b 75 ec             	cmp    -0x14(%ebp),%esi
  802ca8:	74 1e                	je     802cc8 <__udivdi3+0x118>
  802caa:	89 f9                	mov    %edi,%ecx
  802cac:	31 ff                	xor    %edi,%edi
  802cae:	e9 71 ff ff ff       	jmp    802c24 <__udivdi3+0x74>
  802cb3:	90                   	nop
  802cb4:	8d 74 26 00          	lea    0x0(%esi,%eiz,1),%esi
  802cb8:	31 ff                	xor    %edi,%edi
  802cba:	b9 01 00 00 00       	mov    $0x1,%ecx
  802cbf:	e9 60 ff ff ff       	jmp    802c24 <__udivdi3+0x74>
  802cc4:	8d 74 26 00          	lea    0x0(%esi,%eiz,1),%esi
  802cc8:	8d 4f ff             	lea    -0x1(%edi),%ecx
  802ccb:	31 ff                	xor    %edi,%edi
  802ccd:	89 c8                	mov    %ecx,%eax
  802ccf:	89 fa                	mov    %edi,%edx
  802cd1:	83 c4 10             	add    $0x10,%esp
  802cd4:	5e                   	pop    %esi
  802cd5:	5f                   	pop    %edi
  802cd6:	5d                   	pop    %ebp
  802cd7:	c3                   	ret    
	...

00802ce0 <__umoddi3>:
  802ce0:	55                   	push   %ebp
  802ce1:	89 e5                	mov    %esp,%ebp
  802ce3:	57                   	push   %edi
  802ce4:	56                   	push   %esi
  802ce5:	83 ec 20             	sub    $0x20,%esp
  802ce8:	8b 55 14             	mov    0x14(%ebp),%edx
  802ceb:	8b 4d 08             	mov    0x8(%ebp),%ecx
  802cee:	8b 7d 10             	mov    0x10(%ebp),%edi
  802cf1:	8b 75 0c             	mov    0xc(%ebp),%esi
  802cf4:	85 d2                	test   %edx,%edx
  802cf6:	89 c8                	mov    %ecx,%eax
  802cf8:	89 4d f4             	mov    %ecx,-0xc(%ebp)
  802cfb:	75 13                	jne    802d10 <__umoddi3+0x30>
  802cfd:	39 f7                	cmp    %esi,%edi
  802cff:	76 3f                	jbe    802d40 <__umoddi3+0x60>
  802d01:	89 f2                	mov    %esi,%edx
  802d03:	f7 f7                	div    %edi
  802d05:	89 d0                	mov    %edx,%eax
  802d07:	31 d2                	xor    %edx,%edx
  802d09:	83 c4 20             	add    $0x20,%esp
  802d0c:	5e                   	pop    %esi
  802d0d:	5f                   	pop    %edi
  802d0e:	5d                   	pop    %ebp
  802d0f:	c3                   	ret    
  802d10:	39 f2                	cmp    %esi,%edx
  802d12:	77 4c                	ja     802d60 <__umoddi3+0x80>
  802d14:	0f bd ca             	bsr    %edx,%ecx
  802d17:	83 f1 1f             	xor    $0x1f,%ecx
  802d1a:	89 4d f0             	mov    %ecx,-0x10(%ebp)
  802d1d:	75 51                	jne    802d70 <__umoddi3+0x90>
  802d1f:	3b 7d f4             	cmp    -0xc(%ebp),%edi
  802d22:	0f 87 e0 00 00 00    	ja     802e08 <__umoddi3+0x128>
  802d28:	8b 45 f4             	mov    -0xc(%ebp),%eax
  802d2b:	29 f8                	sub    %edi,%eax
  802d2d:	19 d6                	sbb    %edx,%esi
  802d2f:	89 45 f4             	mov    %eax,-0xc(%ebp)
  802d32:	8b 45 f4             	mov    -0xc(%ebp),%eax
  802d35:	89 f2                	mov    %esi,%edx
  802d37:	83 c4 20             	add    $0x20,%esp
  802d3a:	5e                   	pop    %esi
  802d3b:	5f                   	pop    %edi
  802d3c:	5d                   	pop    %ebp
  802d3d:	c3                   	ret    
  802d3e:	66 90                	xchg   %ax,%ax
  802d40:	85 ff                	test   %edi,%edi
  802d42:	75 0b                	jne    802d4f <__umoddi3+0x6f>
  802d44:	b8 01 00 00 00       	mov    $0x1,%eax
  802d49:	31 d2                	xor    %edx,%edx
  802d4b:	f7 f7                	div    %edi
  802d4d:	89 c7                	mov    %eax,%edi
  802d4f:	89 f0                	mov    %esi,%eax
  802d51:	31 d2                	xor    %edx,%edx
  802d53:	f7 f7                	div    %edi
  802d55:	8b 45 f4             	mov    -0xc(%ebp),%eax
  802d58:	f7 f7                	div    %edi
  802d5a:	eb a9                	jmp    802d05 <__umoddi3+0x25>
  802d5c:	8d 74 26 00          	lea    0x0(%esi,%eiz,1),%esi
  802d60:	89 c8                	mov    %ecx,%eax
  802d62:	89 f2                	mov    %esi,%edx
  802d64:	83 c4 20             	add    $0x20,%esp
  802d67:	5e                   	pop    %esi
  802d68:	5f                   	pop    %edi
  802d69:	5d                   	pop    %ebp
  802d6a:	c3                   	ret    
  802d6b:	90                   	nop
  802d6c:	8d 74 26 00          	lea    0x0(%esi,%eiz,1),%esi
  802d70:	0f b6 4d f0          	movzbl -0x10(%ebp),%ecx
  802d74:	d3 e2                	shl    %cl,%edx
  802d76:	89 55 f4             	mov    %edx,-0xc(%ebp)
  802d79:	ba 20 00 00 00       	mov    $0x20,%edx
  802d7e:	2b 55 f0             	sub    -0x10(%ebp),%edx
  802d81:	89 55 ec             	mov    %edx,-0x14(%ebp)
  802d84:	0f b6 4d ec          	movzbl -0x14(%ebp),%ecx
  802d88:	89 fa                	mov    %edi,%edx
  802d8a:	d3 ea                	shr    %cl,%edx
  802d8c:	0f b6 4d f0          	movzbl -0x10(%ebp),%ecx
  802d90:	0b 55 f4             	or     -0xc(%ebp),%edx
  802d93:	d3 e7                	shl    %cl,%edi
  802d95:	0f b6 4d ec          	movzbl -0x14(%ebp),%ecx
  802d99:	89 55 f4             	mov    %edx,-0xc(%ebp)
  802d9c:	89 f2                	mov    %esi,%edx
  802d9e:	89 7d e8             	mov    %edi,-0x18(%ebp)
  802da1:	89 c7                	mov    %eax,%edi
  802da3:	d3 ea                	shr    %cl,%edx
  802da5:	0f b6 4d f0          	movzbl -0x10(%ebp),%ecx
  802da9:	89 55 e4             	mov    %edx,-0x1c(%ebp)
  802dac:	89 c2                	mov    %eax,%edx
  802dae:	d3 e6                	shl    %cl,%esi
  802db0:	0f b6 4d ec          	movzbl -0x14(%ebp),%ecx
  802db4:	d3 ea                	shr    %cl,%edx
  802db6:	0f b6 4d f0          	movzbl -0x10(%ebp),%ecx
  802dba:	09 d6                	or     %edx,%esi
  802dbc:	89 f0                	mov    %esi,%eax
  802dbe:	8b 75 e4             	mov    -0x1c(%ebp),%esi
  802dc1:	d3 e7                	shl    %cl,%edi
  802dc3:	89 f2                	mov    %esi,%edx
  802dc5:	f7 75 f4             	divl   -0xc(%ebp)
  802dc8:	89 d6                	mov    %edx,%esi
  802dca:	f7 65 e8             	mull   -0x18(%ebp)
  802dcd:	39 d6                	cmp    %edx,%esi
  802dcf:	72 2b                	jb     802dfc <__umoddi3+0x11c>
  802dd1:	39 c7                	cmp    %eax,%edi
  802dd3:	72 23                	jb     802df8 <__umoddi3+0x118>
  802dd5:	0f b6 4d f0          	movzbl -0x10(%ebp),%ecx
  802dd9:	29 c7                	sub    %eax,%edi
  802ddb:	19 d6                	sbb    %edx,%esi
  802ddd:	89 f0                	mov    %esi,%eax
  802ddf:	89 f2                	mov    %esi,%edx
  802de1:	d3 ef                	shr    %cl,%edi
  802de3:	0f b6 4d ec          	movzbl -0x14(%ebp),%ecx
  802de7:	d3 e0                	shl    %cl,%eax
  802de9:	0f b6 4d f0          	movzbl -0x10(%ebp),%ecx
  802ded:	09 f8                	or     %edi,%eax
  802def:	d3 ea                	shr    %cl,%edx
  802df1:	83 c4 20             	add    $0x20,%esp
  802df4:	5e                   	pop    %esi
  802df5:	5f                   	pop    %edi
  802df6:	5d                   	pop    %ebp
  802df7:	c3                   	ret    
  802df8:	39 d6                	cmp    %edx,%esi
  802dfa:	75 d9                	jne    802dd5 <__umoddi3+0xf5>
  802dfc:	2b 45 e8             	sub    -0x18(%ebp),%eax
  802dff:	1b 55 f4             	sbb    -0xc(%ebp),%edx
  802e02:	eb d1                	jmp    802dd5 <__umoddi3+0xf5>
  802e04:	8d 74 26 00          	lea    0x0(%esi,%eiz,1),%esi
  802e08:	39 f2                	cmp    %esi,%edx
  802e0a:	0f 82 18 ff ff ff    	jb     802d28 <__umoddi3+0x48>
  802e10:	e9 1d ff ff ff       	jmp    802d32 <__umoddi3+0x52>
